Contents

Useful Docker Commands

Contents

I am trying to compile some useful commands for docker to be a kind of personal repository, if you want me to include something please leave a message

  • docker run <image name> - run a container from the given image
  • docker run --name <name> -d ubuntu bash -c "<command>" - run a ubuntu container giving a name and execute bash and run the
  • docker logs <name> - show the logs for the container named as
  • docker stop $(docker ps -a -q) - to stop all running containers
  • docker rm $(docker ps -a -q) - to remove all stopped containers
  • docker ps -a - to list all containers
  • docker pull ubuntu - pull ubuntu latest image from docker’s hub or repository that is hub.docker.com
  • docker rmi $(docker images -q) - delete all images
  • docker ps –a - view all the running and exited containers
  • docker exec it <container id> bash - access the running container
  • docker stop <container id> - stop the running container
  • docker kill <container id> - stopn and kill a running container
  • docker commit <container id> <username/imagename> - create a new image of the edited container on the local system
  • docker login - login the docker hub repository
  • docker push <username/image name> - push a new image into Docker hub
  • docker port <container name> - show the exposed port for a container
  • docker run --rm -ti -p <ouside_port>:<inside_port> ubuntu bash - create a container fom ubuntu and expose the inside_port from the container to the world in ouside_port
  • docker run --rm -ti --link <container_name> ubuntu:14.04 bash - create a container and link it to the container <container_name>
  • docker network create <network_name> - create a virtual network for containers
  • docker run --rm -ti --net=example --name server ubuntu:14.04 bash - create a container and attach it to a network
  • docker run --rm -ti --net=example --link server --name client ubuntu:14.04 bash - create a container an attach it to a network and to a server in that network
  • docker run -ti -v /shared-data --name <container_name> ubuntu bash - create a container with a volatile volume /shared-data
  • docker run -ti --volumes-from <container_name> ubuntu bash - create a container with a mapping to a volatile volume on <container_name> (i.e /shared-data)