Skip to main content
Blog DevOps

Getting started with Docker – CI/CD and Deployment: Simplifying DevOps

Vel Venkatesh
June 7, 2019 |
docker

What is a Docker?

Docker is an open platform which is used to build, ship and deploy applications using the DevOps process. The main purpose of DevOps is to automate the deployment activity in an efficient way.

Docker aids to automate the deployment activity by writing scripts in the Dockerfile. Then, we can plan out the steps to be followed for successful deployment into new servers or existing servers.

Why Docker?

Docker use the concept of containerisation of the application. You can create containers for your application which will be running independently. You can create containers for front end, backend, DB and all the other services, and you can make all the containers communicate with each other effectively.

You can replicate the number of services for load balance. Everything can be automated, and the process is simple to follow

Dockerfiles should be named ‘Dockerfile’ so that the docker command can find the Dockerfile in the mentioned path.

Dockerfile

  1. FROM ubuntu:16.04
  2. RUN apt-get update -y && apt-get install -y python-pip python-dev && apt-get install -y libmysqlclient-dev && apt-get install -y python-pycurl && apt-get install -y
  3. libcurl4-gnutls-dev && apt-get install -y libgnutls-dev
  4. COPY ./requirements.txt /app/requirements.txt
  5. WORKDIR /app
  6. RUN pip install -r requirements.txt
  7. COPY . /app
  8. EXPOSE 80
  9. ENTRYPOINT [ “python” ]
  10. CMD [ “manage.py” ]
  11. fg
  1. FROM ubuntu:16.04 – Pulls the ubuntu image from the docker registry and created ubuntu image in the local for setting up virtual machine
  2. Run – Installs all the dependencies needed for the application to run the docker machine
  3. COPY – Copies the requirements file into the docker image
  4. WORKDIR – Sets the working directory in the ubuntu image
  5. RUN pip install -r requirements.txt – Installs all the packages in a requirements file
  6. COPY . /app – Copies the current folder data into an app folder inside docker
  7. EXPOSE 80 – Exposes the port 80 for incoming connections
  8. Entrypoint – Sets the entrypoint command as python
  9. CMD – Sets the execution command as manage.py

Build Docker Image

  1. You can build your docker image in a single command.
  2. docker build -t cloras .
  3. -t {name} → cloras – Refers to the tag name which is the name of the image
  4. . → Refers to the path where Dockerfile is located(. Refers to current path)
  5. You can see the nine steps being run by the above command. As the end result, an image has been created after all the steps.
  6. The below command can list out all the images, as seen below.

Create Networks and Containers

  • A network is something that connects two or more containers. If you want your containers to communicate between them, then you must create networks and run your containers using the network.
  • The below command will create networks:
  • docker create network my_app
    my_app → Name of the network
  • The below command will create containers using the created network:
    docker run –net my_app -p 8443:8443 -p 2020:2020 cloras
    docker run –net my_app redis redis
    –net – refers to network
    -p – refers to port
    Note:- In the above command, we are defining two ports. The first port defines the internal port and the second one defines the external port. If we want to connect to the running container from the browser, we will use the external port.
    We are creating two containers using the same network, in order to create communication between the containers.
  • The below command will list out the running containers:
    docker ps
  • The below command will list out all the containers:
    docker ps -a

Now, you can see the running containers after executing the commands. You can browse the exposed hosts and ports.

The above mentioned steps are for a basic understanding of what dockers and containers are and why you need them.

Vel Venkatesh

Full Stack Developer, Experienced with Python and web frameworks(Django, Flask). Also experienced with working in DevOps at minor level.

More posts by Vel Venkatesh