Skip to content

Instantly share code, notes, and snippets.

@drewmace
Last active January 5, 2017 12:11
Show Gist options
  • Save drewmace/f78dd690458a9561db1d73e52edb4456 to your computer and use it in GitHub Desktop.
Save drewmace/f78dd690458a9561db1d73e52edb4456 to your computer and use it in GitHub Desktop.
Docker common commands

Docker Commands

List images:

docker images

List running docker processes:

docker ps

List all processes that were ever run:

docker ps -a

List only the container IDs:

docker ps -a -q

Running processes:

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

Tail logs in a container

docker logs -f <container_id> = tail the logs of the container

Remove unused volumes

docker volume rm $(docker volume ls -qf dangling=true)

Cleaning up Docker:

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

Redirect port:

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

Adding volume:

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

Building a Docker file:

docker login --username=<username>
Enter password
docker push username/repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment