Run an image in a new container daemonized
$ sudo docker run -d <image_name>
Run an image in interactive mode with the command /bin/bash
$ sudo docker run -i -t <image_name> /bin/bash
Run an image in interactive mode with the command /bin/bash
and link the ports.
$ sudo docker run -i -t --link <docker_container_name>:<docker_container_alias> <image_name> /bin/bash
Run an image in interactive mode with the command /bin/bash
mounting the host director /var/app/current
to the container directory /usr/src/app
$ sudo docker run -i -t -v /var/app/current:/usr/src/app/ <image_name> /bin/bash
Run an image in interactive mode with the command /bin/bash
setting the environments variables FOO
and BAR
$ sudo docker run -i -t -e FOO=foo -e BAR=bar <image_name> /bin/bash
Stops all running containers
$ docker stop $(docker ps -a -q)
Kill all running containers
$ docker kill $(docker ps -q)
Delete all stopped containers
$ docker rm $(docker ps -a -q)
List all the images
$ docker images -a
Clean up any resources - images, containers, volumes, and networks - that are dangling (not associated with a container)
to additionally remove any stopped containers and all unused images (not just dangling images), add the -a
flag to the command
$ docker system prune -a
Rebuild docker image before starting container, if you don't specify <service_name>
docker will rebuild all the images
$ docker-compose up -d --no-deps --build <service_name>