Skip to content

Docker

Docker is a platform for building, running, and managing containerized applications. It simplifies the process of software development, deployment, and management by providing a lightweight, portable, and self-contained environment for applications. Docker is based on the concept of containers, which are isolated and self-sufficient environments that package up an application's code, libraries, dependencies, and runtime.

Create your Dockerhub account

  1. Goto DockerHub
  2. Click Sign Up and create your account

Installing Docker

Let's use the EC2 instance for understanding the concepts of docker and later you can install it on your laptop or desktop using Docker Desktop

  1. Login into one of the EC2 instance that you have it running.
  2. Once you SSH into the instance, issue the below commands
shell
sudo yum install docker
shell
sudo usermod -a -G docker ec2-user
shell
newgrp docker
shell
sudo systemctl enable docker.service
shell
sudo systemctl start docker.service
  1. To check if your docker is up and running run ps command
docker ps
  1. To test if the docker is installed properly, you will use hello-world image from docker repository
shell
docker pull hello-world
docker run hello-world
  1. In order to test if you can access the service running inside the docker you can install an nginx server and try accessing using Public IP from your EC2 instance
shell
docker pull nginx
docker run -it --rm -d -p 8080:80 --name web nginx
  1. When you access the port 8080 from your browser with your EC2 instance IP address http://PUBLIC_IP:8080 you will see below output.
text
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

Note

If you dont see the output on browser and rather see timeouts, then you need to open the security group inbound rules to allow this port 8080 being accessed.

Essential Docker commands

docker run: Starts a new Docker container from an image.

docker ps: Lists all running Docker containers.

docker stop: Stops a running Docker container.

docker rm: Removes a Docker container.

docker images: Lists all Docker images available on the system.

docker pull: Pulls a Docker image from a registry.

docker exec: Executes a command in a running container.

docker build: Builds a Docker image from a Dockerfile.

docker push: Pushes a Docker image to a registry.

docker logs: Shows the logs of a running or stopped container.

Released under the MIT License. Some of the contents are generated using Gen AI