1

I have created a container with docker-compose in which there are two images with a Django application deployed (nginx to serve the static files and gunicorn as the web server). I want to share that container with people, but I don't know how to do it. I have read this question from another user and this one but I can't quite understand it ...

This is my container:

container created with docker-compse

But when I run docker ps -a to see my containers, I don't get just one, I get 2 ...:

(venv) C:\Users\jmartinpe\Desktop\django_pegaso>docker ps -a
CONTAINER ID   IMAGE                             COMMAND                  CREATED        STATUS                        PORTS     NAMES
fea9f3f1f513   f455afd8b6b7                      "/docker-entrypoint.…"   33 minutes ago   Exited (0) 12 minutes ago               django_pegaso_nginx_1
36e7a1c41d28   18df3392ccd3                      "sh /entrypoint.sh"      33 minutes ago   Exited (137) 12 minutes ago             django_pegaso_django_gunicorn_1

And these are the two images that make up the container:

(venv) C:\Users\jmartinpe\Desktop\django_pegaso>docker images
REPOSITORY                      TAG       IMAGE ID       CREATED          SIZE
django_pegaso_django_gunicorn   latest    18df3392ccd3   33 minutes ago   459MB
django_pegaso_nginx             latest    f455afd8b6b7   2 hours ago      21.3MB

How could I export the container with the two images? With docker save Image> myImage.tar it would only export an image, right?

This is my my docker-compose.yml:

version: '3.8'

services:
  django_gunicorn:
    volumes:
      - static:/static
    env_file:
      - .env
    build:
      context: .
    ports:
      - "8000:8000"
  nginx:
    build: nginx
    volumes:
      - static:/static
    ports:
      - "8080:8080"
    depends_on:
      - django_gunicorn

volumes:
  static:

UPDATE:

I have tried, as suggested in the comments, to save the images and move the two images together to the docker-compose.yml file to a directory, and run docker-compose up from that folder, but it gives me the error Error response from daemon: pull access denied for django_pegaso_nginx, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.

(venv) C:\Users\jmartinpe\Desktop\django_pegaso>docker images
REPOSITORY                      TAG       IMAGE ID       CREATED         
SIZE
django_pegaso_django_gunicorn   latest    0265e0881fbe   2 minutes ago               459MB
django_pegaso_nginx             latest    f455afd8b6b7   19 hours ago    21.3MB
django_pegaso_debug             latest    c6b50343f25b   24 hours ago    750MB

(venv) C:\Users\jmartinpe\Desktop\django_pegaso>docker save 0265e0881fbe > django_pegaso_django_gunicorn.tar

(venv) C:\Users\jmartinpe\Desktop\django_pegaso>docker save f455afd8b6b7 > django_pegaso_nginx.tar

The steps I have followed have been:

  1. Save the images
  2. Move them to the same directory
  3. Create the docker-compose.yml in that directory
  4. Run docker-compose up

EDIT2:

I got it! Here is the guide that has helped me, in case it helps more people: https://eking-30347.medium.com/exporting-multiple-docker-images-alongside-docker-compose-f2db5d4a1632

jmp
  • 71
  • 9
  • 2
    You have a Compose stack consisting of _two_ containers with _two_ separate images; they're just grouped together in the Docker Desktop UI. The easiest approach here is to probably push the application image to some registry and commit the `docker-compose.yml` file to source control. – David Maze Sep 01 '21 at 14:37
  • Yes, it's just what you say. After researching quite a while I have found this: https://eking-30347.medium.com/exporting-multiple-docker-images-alongside-docker-compose-f2db5d4a1632 I'm trying to pull it off, but I think I'm doing something wrong in the final docker-compose.yml. If I can't, I'll update the question to see if you can help me out. It's the first time I've used Docker and it's a bit complex for me. – jmp Sep 01 '21 at 14:45
  • the tutorial shows what to do with containers that save some info in them, with ephemeral applications committing the containers to a new image isn't needed. In your case, you just need to `docker save` the images and tar zip or rar the images and the compose file to a single file to transfer to another machine – Noam Yizraeli Sep 01 '21 at 16:44

0 Answers0