docker run <image-name>:<version>
docker ps
List all running as well as previously stopped containers.
docker ps -a
docker stop <container-name-or-id>
docker rm <container-name-or-id>
docker rm $(docker ps -aq)
docker images
You should be ensure the container is not running using this image.
docker rmi <image-name>
docker rmi <repository-name>:<version>
Pulls nginx image without run.
docker pull nginx
Some containers don't run forever. For ex: ubuntu image.
Run a container for a 5 seconds.
docker run ubuntu sleep 5
Prints the etc/hosts file inside the container
docker exec <container-name-or-id> cat /etc/hosts
docker run <container-name-or-id>
docker run -d <container-name-or-id>
docker run --name <explicit-name> <image-name>
This command maps traffic comes from port 80 to 5000 port in docker host. We can also create more instances on the same container
docker run -p 80:5000 redis
This command mounts the var/lib/mysql folder to the /opt/datadir folder which exist in the docker host.
docker run -v /opt/datadir:/var/lib/mysql mysql
docker inspect <container-name-or-id>
docker logs <container-name-or-id>
docker -H=remote-docker-engine:2375
docker build . -f Dockerfile -t <image-name>
docker push <image-name>
We can pass an environment variable to the source code lives in container.
docker run -e ENV-VAR-NAME=value <image-name>
We can now inspect the variable with:
docker inspect <container-name-or-id>
docker compose up
docker network
Create a new network named wp-mysql-network using the bridge driver. Allocate subnet 182.18.0.1/24. Configure Gateway 182.18.0.1
docker network create --driver bridge --subnet 182.18.0.1/24 --gateway 182.18.0.1 wp-mysql-network
Deploy a mysql database using the mysql:5.6 image and name it mysql-db. Attach it to the newly created network wp-mysql-network Set the database password to use db_pass123. The environment variable to set is MYSQL_ROOT_PASSWORD
docker run -d -e MYSQL_ROOT_PASSWORD=db_pass123 --name mysql-db --network wp-mysql-network mysql:5.6