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 imagedocker run --name <name> -d ubuntu bash -c "<command>"
- run a ubuntu container giving a nameand execute bash and run the docker logs <name>
- show the logs for the container named asdocker stop $(docker ps -a -q)
- to stop all running containersdocker rm $(docker ps -a -q)
- to remove all stopped containersdocker ps -a
- to list all containersdocker pull ubuntu
- pull ubuntu latest image from docker’s hub or repository that is hub.docker.comdocker rmi $(docker images -q)
- delete all imagesdocker ps –a
- view all the running and exited containersdocker exec it <container id> bash
- access the running containerdocker stop <container id>
- stop the running containerdocker kill <container id>
- stopn and kill a running containerdocker commit <container id> <username/imagename>
- create a new image of the edited container on the local systemdocker login
- login the docker hub repositorydocker push <username/image name>
- push a new image into Docker hubdocker port <container name>
- show the exposed port for a containerdocker 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_portdocker 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 containersdocker run --rm -ti --net=example --name server ubuntu:14.04 bash
- create a container and attach it to a networkdocker 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 networkdocker run -ti -v /shared-data --name <container_name> ubuntu bash
- create a container with a volatile volume /shared-datadocker 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)