Created
May 15, 2018 17:14
-
-
Save srpatcha/6425d0beb4156bab317e30b9908ab9c3 to your computer and use it in GitHub Desktop.
Docker Help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Help : https://devhints.io/ | |
#List local available images | |
$ docker images | |
$docker run <image> | |
$docker run -d <image> = run in disconnected / daemon mode | |
$docker run --name="Some Name" = name the running instance | |
$docker start <name> = will restart a closed / exited instance of the image | |
$docker exec -it <name> <command> = run a command within a running container without changing the state of the running container | |
$docker stop <name> = stop a running container by using the name | |
$docker rm containerid = removes an instance of the container that was run | |
$docker rm `docker ps -a -q` = remove all stopped containers | |
$docker rmi image-name = removes the docker image and its dependencies | |
$docker run -P = will redirect the container's port to a random port on the host machine's user port (port no 32,000+) | |
$docker run -p 8080:80 = will redirect the container's port 80 to a port 8080 on the host machine's user port | |
$docker port <container-name> = will list the port mapping information | |
using the "-v" option mounts the local file system. eg to mount for an nginx on centos | |
-v /home/user/www:/usr/share/nginx/html | |
$docker login --username=<username> #Enter password | |
docker status check | |
$ps -ef | grep docker | |
#add user to docker group | |
$sudo usermod -aG docker $USER | |
$sudo gpasswd -a $USER docker # adding user to sudo permissions on docker | |
$getent group sudo | |
$getent group docker | |
Sample Json file : /etc/docker/daemon.json | |
{ | |
"insecure-registries": [ "f7engr090.cg.na.nodegos.com:5000" ], | |
"dns": [ "11.15.43.57", "10.11.34.67" ], | |
"storage-driver": "overlay2" | |
} | |
List docker process : | |
$docker ps -a | |
List Dockers images: | |
$docker images | |
Example "jenkins" user docker launch : | |
$docker run -u jenkins -it -v ~/.ssh:/home/jenkins/.ssh -w /home/jenkins/workspace local-nodegos-wrlinux:latest bash | |
Service restart Ubuntu: | |
$service docker restart | |
$sudo systemctl daemon-reload # reload systemd | |
$sudo systemctl restart docker # now reload dockerd | |
Start a container in background | |
$ docker run -d jenkins | |
Start an interactive container | |
$ docker run -it ubuntu bash | |
Export port from a container | |
$ docker run -p 80:80 -d nginx | |
Start a named container | |
$ docker run --name mydb redis | |
Restart a stopped container | |
$ docker start mydb | |
Stop a container | |
$ docker stop mydb | |
Add metadata to container | |
$ docker run -d label=traefik.backend=jenkins jenkins | |
Build an image from Dockerfile in current directory | |
$ docker build --tag myimage . | |
Manage Containers | |
List running containers | |
$ docker ps | |
Force rebuild of Docker image | |
$ docker build --no-cache . | |
Convert a container to image | |
$ docker commit c7337 myimage | |
Run another process in running container | |
$ docker exec -it c7337 bash | |
Show live logs of running daemon container | |
$ docker logs -f c7337 | |
Show exposed ports of a container | |
$ docker port c7337 | |
List all containers ( running & stopped ) | |
$ docker ps -a | |
Delete all stopped containers | |
$ docker rm $(docker ps --filter status=exited -q) | |
Create a local volume | |
$> docker volume create --name myvol | |
Mounting a volume on container start | |
$> docker run -v myvol:/data redis | |
Destroy a volume | |
$ docker volume rm myvol | |
List volumes | |
$ docker volume ls | |
Create a local network | |
$ docker network create mynet | |
Attach a container to a network on start | |
$ docker run -d --net mynet redis | |
Connect a running container from a network | |
$ docker network connect mynet c7337 | |
Disconnect container to a network | |
$ docker network disconnect mynet c7337 | |
List all containers with a specific label | |
$ docker ps --filter label=traefik.backend | |
Inspect containers metadatas | |
$ docker inspect c7337 | |
Start a container automatically removed on stop | |
$ docker run --rm ubuntu bash | |
Query a specific metadata of a running container | |
$ docker inspect -f '{{ .NetworkSettings.IPAddress }}' c7337 | |
Remove all unused images | |
$ docker rmi $(docker images -q -f "dangling=true" | |
$ docker-compose up -d # start containers in background | |
$ docker-compose kill # stop containers | |
$ docker-compose up -d --build # force rebuild of Dockerfiles | |
$ docker-compose rm # remove stopped containers | |
$ docker ps # see list of running containers | |
$ docker exec -ti [NAME] bash # ssh to the container | |
#tag and publishing | |
$docker tag <id> buonzz/name:version | |
docker login | |
$docker push buonzz/name | |
delete image | |
$docker rmi -f <id> | |
run an image | |
$docker run yourusername/docker-whale | |
view logs | |
$docker logs [OPTIONS] CONTAINER | |
set the port to expose in host | |
$docker run -p 3000 my_image | |
start new container interactively | |
$ docker container run -it | |
$ docker-compose up -d # start containers in background | |
$ docker-compose kill # stop containers | |
$ docker-compose up -d --build # force rebuild of Dockerfiles | |
$ docker-compose rm # remove stopped containers | |
$ docker ps # see list of running containers | |
$ docker exec -ti [NAME] bash # ssh to the container | |
# tag and publishing | |
docker tag <id> buonzz/name:version | |
docker login | |
docker push buonzz/name | |
# delete image | |
docker rmi -f <id> | |
# run an image | |
docker run yourusername/docker-name | |
# view logs | |
docker logs [OPTIONS] CONTAINER | |
# set the port to expose in host | |
docker run -p 3000 my_image | |
# start new container interactively | |
docker container run -it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment