Automatic Tweet Liker using Tweepy and Django - Part 2

Using Dockerfile to setup environment and docker-compose to automatically configure application services.

Image from cleanpng

Dockerfile:

Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could execute on the command line to assemble an image. Dockerfile should be named as “Dockerfile” without any extension. This Dockerfile should exist in the project folder i.e. AutoTweetLiker/.

FROM python:3.7-alpineENV PYTHONONBUFFERED 1RUN mkdir /codeWORKDIR /codeCOPY . /code/RUN pip install -r requirements.txt

Docker-compose:

Compose is a tool for defining and running multi-container Docker applications. With Compose, we use a YML/YAML file to configure our application’s services. Then, with a single command, we create and start all the services from your configuration. Docker-compose file should be named as “docker-compose” with a YML/YAML extension. This docker-compose.yml file should exist in the project folder i.e. AutoTweetLiker/.

version: '3'services:    web:        build: .        # Exporting CONSUMER KEY and CONSUMER SECRET key from  tweeter api as an environment variable        command: sh -c "export CONS_KEY=""            && export CONS_SECRET=""            && python manage.py runserver 0.0.0.0:8000"        volumes:            - .:/code        ports:            - "8000:8000"

Getting the project source code:

You will get the project source code from the docker branch from https://github.com/cankush625/AutoTweetLiker.git OR clone the repository by using the following command.

git clone -b docker https://github.com/cankush625/AutoTweetLiker.git

Building and Launching the project:

Open the terminal in the directory where our Dockerfile and docker-compose.yml files exist. Run the following command to build the docker image for the project.

# docker-compose build
docker-compose build
# docker-compose up
docker-compose up
# docker-compose stop
# docker-compose start
# docker-compose down

Tech blogger, researcher and integrator