Docker Lab Manual
This lab manual will guide you through the basic operations and commands required to work
with Docker. You will learn how to install Docker, run containers, manage container processes,
and set up a full web application using Docker Compose.
Lab 1: Installing Docker and Its Basic Commands
Steps
1. Install Docker Desktop
- Download and install Docker Desktop from the official [Docker
website](https://www.docker.com/products/docker-desktop).
- Follow the installation instructions for your operating system.
2. Verify Installation
- Open the terminal.
- Run the following command:
docker --version
3. Open dockerhub and see various available images
Visit https://hub.docker.com/
4. Create Image on local machine
docker run -e POSTGRES_PASSWORD=password postgres:9.6
5. To see list of running images :: docker ps
docker run -e POSTGRES_PASSWORD=password postgres
docker ps
6. Pulling of image from dockerhub to local machine, it will not create container, only image
will be created on local machine.
docker pull redis
To see list of images
docker images
docker run redis
docker ps
To stop running container
Go in to running container of redis and write ctrl c it will stop
Run docker ps to cross check
To running in detach mode
docker run -d redis
To stop a Container
docker stop container_id
To start a Container
docker start container_id
To get container_id of previous running dockers
Because to start you need container_id
docker ps -a
Note: docker run redis // Run command is a combination of pull and start
Lab-2: Port Binding and Running Multiple Containers
Concept of Ports
To understand this let have two versions of redis
docker run redis:7.2
docker run redis
Both are using same port as shown below
Stop both redis container by using docker stop or ctrl c as shown below.
And then use run command with port binding option -p as shown
docker run -p6000:6379 redis
This will bind default 6379 port to laptop 6000 port
Check Ports with docker ps command
Run redis: 7.2 with different port number as shown below
Note: If you try to use same port second time you will get an error
Docker Debugging
To see the logs for a particular container.
docker logs fe795eafbe53
Or you can use
docker logs give_names_here
To Give own Docker name
Use – name with run command
Giving own name and port number
PS C:\Users\parte> docker run -d -p6000:6379 --name redis_latest redis
Check name and port numbers
Doing this for second container
To get insider the docker
docker exec -it 48412bf7af71 /bin/bash
-it means interactive terminal
inside this u can check environmental variables using env
To come out write exit
Difference between docker run and docker start
Docker run create a new container for the specific image, Once you have the container you
can start or stop it