Basic and advanced docker commands for reference. Use them as a cheat sheet
- Commands to install docker on Linux
curl -fsSL https://get.docker.com -o get-docker.shsudo sh get-docker.sh
- Command to start the Docker daemon
sudo service --status-allsudo service docker start
- Command to Pull the docker images from Docker hub - https://hub.docker.com/
docker pull image_name:version
version : default value is latest
docker pull mysql
- Command to pull and install the docker image
docker run image_namedocker run mysql
docker run -d image_name => To run the command in background mode.
docker run -d --name webapp_vk -d image_name => To assign a name to the docker container
docker run -d image_name command ==> We will override the CMD statement in the image or append the value to ENTRYPOINT command.
- Command to List the running containers.
docker ps ==> List all the running containers.
docker ps -a ==> List both running and stopped containers.
- Command to List the images present on the host.
docker images ==> List all the images.
- Command to Stop the containers.
docker stop container_id / container_name.
- Command to Remove the containers.
docker rm container_id ==> Make sure containers are stopped before running the command.
- Command to delete or remove the images.
docker rmi image_id ==> We can specify first few characters of the Id.
- Command to run and execute Unix command.
docker run ubuntu cat /etc/*releases* ==> This will install a ubuntu on a container and run the command.
- Command to execute the scripts
docker exec container_id cat /etc/*release*
- Command to build a docker image
docker build . ==> provided the Dockerfile is in the same directory from where we are running this command.
docker build -f DockerFile -t vijaya/image_name ==> Providing tag/name to the image
- Command to push the docker image to Hub
Before we push the image , we need to login
docker login ==> This will prompt docker hub credentials. After successful login
docker push vijaya/image_name ==> Push the image to Hub
- Command to pass the environment values
docker run -d -e ENV_VARIABLE_NAME=VALUE --name vijaya_container image_name ==> This will supply the environment values.
- Command for Port Mapping to access the applications using Docker Host IP.
docker run -d -p host_port : container_port image_name
docker run -d -p 8306:3306 mysql
No comments:
Post a Comment