docker run image_name
To run a specific version use a tag. By default tag is 'latest'
docker run image_name:version
Give a container name while running an image
docker run --name container_name image_name
docker run -d image_name
Above command returns ID of the container. To attach to the container use
docker attach container_ID
Providing first few letters of the ID works fine.
To view logs of a container running in detached mode use
docker logs container_name
docker run -it image_name
docker run -p host_port:container_port image_name
Now the application running on the docker container at http://CONTAINER_IP:CONTAINER_PORT can be accessed from outside the container at http://HOST_IP:HOST_PORT
docker run -v external_host_directory:container_directory image_name
docker ps
docker ps -a
docker stop container_name
docker rm container_name
docker images
docker rmi image_name
docker pull image_name
docker exec container_name command
Example: docker exec nginx_container cat /etc/hosts
docker inspect container_name
docker run -e ENV_VAR_NAME=VALUE image_name
docker inspect container_name | grep ENV_VAR_NAME
docker build Dockerfile -t account_name/image_name
docker push account_name/image_name
docker run image_name --network=network_name
docker network create --driver bridge --subnet SUBNET_IP_RANGE --gateway GATEWAY_ADDR custom_isolated_network_name
docker network ls
docker volume create volume_name
docker run -v PATH_TO_EXTERNAL_VOLUME:PATH_IN_CONTAINER image_name
If external volume is not already created, docker creates it in /var/lib/docker/volumes directory.
Can also be written as
docker run --mount type=bind, source=PATH_TO_EXTERNAL_VOLUME, target=PATH_IN_CONTAINER image_name
docker-compose up
docker run --link NAME_OF_CONTAINER_TO_BE_LINKED:CONTAINER_THE_IMAGE_IS_LOOKING_FOR image_name
docker -H=remote_host_IP_addr:remote_host_PORT run image_name
docker swarm init
This returns a token for workers/slaves to join
docker swarm join --token <token>
docker service create --replicas=NUM_OF_REPLICAS image_name
To be run on the Swarm Manager.