Docker-compose.yml

600x400
  1. Version:- Specifies the docker-Compose 'version:' and this version does't relate directly to the version of docker-compose that you have installed this is just a version of docker-compose file format that we wish to write.
  2. Services:- This section defines the containers that will be started as a part of the Docker Compose instance.
  3. Networks:- This section is used to configure networking for your application. You can change the settings of the default network, connect to an external network, or define app-specific networks.
  4. Volumes:- Mounts a linked path on the host machine that can be used by the container.
version: '2'
services:

networks:
  main:
    driver: bridge

volumes:
  scan_file:
  1. Image:- Sets the image that will be used to build the container and also use existing docker file from Docker Hub.
  2. Build:- Specifies the location of the Dockerfile that will be used to build the container.
  3. Name_of_service:- name_of_service is a keyword that used to define number of separate services. like:- db and web
  4. Restart:- Tells the container to restart if the system restarts.
  5. Environment:- Environment variables are available to processes running inside of Docker containers.
  6. Depends_on:- Docker-compose up starts services in dependency order.
  7. Port:- Ports in the HOST:CONTAINER format, container build in container port and we can browse it in host port
  8. Link:- Link this service to any other services in the Docker Compose file by specifying their names here.
db:
      image: mysql
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: 123
        MYSQL_DATABASE: nlp_alex
      
      networks:
        - main

    web:
      restart: always
      image: nlp
      command: python manage.py
      
      ports:
        - "2226:5001"

      links:
        - db
      depends_on:
        - db
      networks:
        - main

Dockerfile

  1. From:- Name of the base image that used to start the process.
  2. Run:- It takes a command as its argument and runs it to form the image.
  3. Add:- Add command gets two arguments a source and a destination. It basically copies the files from the source on the host into the container's own filesystem at the set destination. COPY and ADD are both Dockerfile instructions that use for similar purposes.
  4. WORKDIR: The WORKDIR directive is used to set where the command defined with CMD is to be executed.
  5. ENTRYPOINT:- ENTRYPOINT argument sets the concrete default application that is used every time a container is created using the image.
  6. ENV:- ENV command is used to set the environment variables.
  7. CMD:- CMD can be used for executing a specific command within the container.
  8. EXPOSE:- A specific port to enable networking between the container and the outside world.
FROM ubuntu:18.04
COPY . /app
RUN make /app
CMD python /app/app.py