Answers: <p>In the directory containing the <code>docker-compose.yml</code> one can do:</p>
  <ol>
  <li>Start containers (detached mode): <code>docker-compose up -d</code></li>
  <li>Stop containers: <code>docker-compose down --remove-orphans</code></li>
  </ol>
  
Answers: CC BY-SA 4.0
Answers: 2023-09-01T11:09:34.080Z
Answers: 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?
Answers: Levan Lomidze
Answers: CC BY-SA 4.0
Answers: 2023-09-01T12:42:23.290Z
Answers: @LevanLomidze can your production server access DockerHub? Are you using DockerHub and a private Docker registry?
Answers: mikequentel
Answers: CC BY-SA 4.0
Answers: 2023-09-01T13:56:26.627Z
Answers: yes my productions server have access to DockerHub. It is public DockerHub and public images.
Answers: Levan Lomidze
Answers: CC BY-SA 4.0
Answers: 2023-09-01T18:05:50.063Z
Answers: 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
Answers: mikequentel
Answers: CC BY-SA 4.0
Answers: 2023-08-31T02:18:33.317Z
Answers: 2023-08-31T02:18:33.317Z
Answers: mikequentel
Answers: <p>Okay, I got the answer.</p>
  <p>To use my DockerHub images on production I need special docker-compose file, without build detective. This is the work example in my case:</p>
  <pre><code>version: '3.9'
  
  volumes:
    static:
  
  services:
    demo:
      image: findsimilar/demo
      restart: always
      expose:
        - 8080
      volumes:
        - static:/static/
      command: bash -c &quot;
        python manage.py collectstatic --noinput -- 
     settings=demo.prod_settings
    &amp;&amp; gunicorn demo.wsgi -b 0.0.0.0:8080
    &quot;
    nginx:
      image: findsimilar/demo-nginx
      restart: always
      ports:
        - 80:80
      volumes:
        - static:/etc/nginx/static/
      depends_on:
        - demo
  </code></pre>
  <p>The file is similar with docker-compose in the question but without <code>build</code> and <code>context</code></p>
  <p>I did <code>docker compose pull</code> and <code>docker compose up -d</code> on my server and it worked.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-09-01T15:51:00.040Z
Answers: 2023-09-01T15:51:00.040Z
Answers: Levan Lomidze
Body: <p>I have the <code>docker-compose</code> file with two containers. &quot;nginx&quot; container depends on &quot;demo&quot; (it's python django backend).</p>
  <pre><code>version: '3.9'
  
  volumes:
    static:
  
  services:
    demo:
      image: findsimilar/demo
      build:
        context: .
      restart: always
      expose:
        - 8080
      volumes:
        - static:/static/
      command: bash -c &quot;
        python manage.py collectstatic --noinput --settings=demo.prod_settings
        &amp;&amp; gunicorn demo.wsgi -b 0.0.0.0:8080
        &quot;
    nginx:
      image: findsimilar/demo-nginx
      build: ./nginx
      restart: always
      ports:
        - 80:80
      volumes:
        - static:/etc/nginx/static/
      depends_on:
        - demo
  </code></pre>
  <p>I've done <code>docker compose build</code> and <code>docker compose push</code>.
  Images have been pushed on DockerHub.</p>
  <p>The question is &quot;How can I properly use this images on production server?&quot;
  I've tried <code>docker run findsimilar/demo</code> and <code>docker run findesimilar/demo-nginx</code>.
  The images have been pulled but <code>findsimilar/demo</code> haven't been started and <code>findsimilar/demo-nginx</code> didn't find a demo:8080 host.</p>
  
Tags: <docker><docker-compose><dockerhub>
Title: How can I use two different docker container on the production server (after pushing to DockerHub)?
UserDisplayName: Levan Lomidze
ThreadText: # How can I use two different docker container on the production server (after pushing to DockerHub)?
  
  (Asked by: username_0 on 2023-08-29)
  
  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.
  
  **Tags:** docker, docker-compose, dockerhub
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-08-31. Score: 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`
  
  > **Comments:**
  > **username_0**: 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?  
  > **username_1**: @username_0 can your production server access DockerHub? Are you using DockerHub and a private Docker registry?  
  > **username_0**: yes my productions server have access to DockerHub. It is public DockerHub and public images.  
  > **username_1**: 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  
  
  ---
  
  ### Answer by username_0 on 2023-09-01. Score: 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.
  
  
  ---
  
  