Getting Started with Docker

What is Docker? 

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package  an application with all the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

Benefits Of Docker.

  • Standardization & productivity
  • Compatibility & maintainability.
  • Simplicity & faster configurations
  • Rapid Deployment
  • Continuous Deployment & Testing

I want to use docker

1. Install Docker on your OS

On Mac: https://download.docker.com/mac/stable/Docker.dmg

Windows: https://store.docker.com/editions/community/docker-ce-desktop-windows

2. Create a DockerFile/ Download an exiting docker file. It is also called a Docker image

docker pull nginx

Source: https://hub.docker.com/_/nginx/

It will download the latest docker file from

https://github.com/nginxinc/docker-nginx

 

Lets check if the docker image is downloaded

docker images

You should be able to see the nginx “image”

3. Create a running container out of an image

docker run --name my-nginx-container -d nginx

You will see a container Id on your screen. It means the container is running.

4. How do I know docker container is running?

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5da9156d8480 nginx "nginx -g 'daemon ..." 51 seconds ago Up 51 seconds 80/tcp my-nginx-container.

This means the container is running and you can cross check first few characters of the containerId

5. How do I know what is running inside the container?

Let’s map a port from the outside (your laptop) to a docker port (inside the container)

Outside port: 8080

Docker Port: 80

(In this case, a new container will be created)

docker tun --name my-nginx-container2 -d -p 8080:80 nginx

Reach port 8080 on localhost

curl localhost:8080

Voila !! nginx is running on your machine inside a Docker container.

READ: https://hub.docker.com/r/_/nginx/ for more info and complex cases.

3,332 Replies to “Getting Started with Docker”