0

I have the docker-compose file with two containers. "nginx" container depends on "demo" (it's python django backend).

version: '3.9'

volumes:
  static:

services:
  demo:
    image: findsimilar/demo
    build:
      context: .
    restart: always
    expose:
      - 8080
    volumes:
      - static:/static/
    command: bash -c "
      python manage.py collectstatic --noinput --settings=demo.prod_settings
      && gunicorn demo.wsgi -b 0.0.0.0:8080
      "
  nginx:
    image: findsimilar/demo-nginx
    build: ./nginx
    restart: always
    ports:
      - 80:80
    volumes:
      - static:/etc/nginx/static/
    depends_on:
      - demo

I've done docker compose build and docker compose push. Images have been pushed on DockerHub.

The question is "How can I properly use this images on production server?" I've tried docker run findsimilar/demo and docker run findesimilar/demo-nginx. The images have been pulled but findsimilar/demo haven't been started and findsimilar/demo-nginx didn't find a demo:8080 host.

2 Answers 2

0

In the directory containing the docker-compose.yml one can do:

  1. Start containers (detached mode): docker-compose up -d
  2. Stop containers: docker-compose down --remove-orphans
4
  • Thanks. Containers run properly on local machine with docker compose up. And I if put all the project on the production server it runs too. But I don't really understand the role of DockerHub. Can I just push images in DockerHub and run this images on production or I need all the project structure in production server anyway? Sep 1, 2023 at 11:09
  • @LevanLomidze can your production server access DockerHub? Are you using DockerHub and a private Docker registry? Sep 1, 2023 at 12:42
  • yes my productions server have access to DockerHub. It is public DockerHub and public images. Sep 1, 2023 at 13:56
  • If the production server can access DockerHub, it should be able to pull the versions of the Docker images, as needed, when running docker-compose Sep 1, 2023 at 18:05
0

Okay, I got the answer.

To use my DockerHub images on production I need special docker-compose file, without build detective. This is the work example in my case:

version: '3.9'

volumes:
  static:

services:
  demo:
    image: findsimilar/demo
    restart: always
    expose:
      - 8080
    volumes:
      - static:/static/
    command: bash -c "
      python manage.py collectstatic --noinput -- 
   settings=demo.prod_settings
  && gunicorn demo.wsgi -b 0.0.0.0:8080
  "
  nginx:
    image: findsimilar/demo-nginx
    restart: always
    ports:
      - 80:80
    volumes:
      - static:/etc/nginx/static/
    depends_on:
      - demo

The file is similar with docker-compose in the question but without build and context

I did docker compose pull and docker compose up -d on my server and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.