1

I have a docker compose application, which works fine in local. I would like to create an image from it and upload it to the docker hub in order to pull it from my azure virtual machine without passing all files. Is this possible? How can I do it?

I tried to upload the image I see from docker desktop and then pull it from the VM but the container does not start up.

Here I attach my .yml file. There is only one service at the moment but in the future there will be multiple microservices, this is why I want to use compose.

    version: "3.8"
    services:
      dbmanagement:
        build: ./dbmanagement
        container_name: dbmanagement
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
          - ./dbmanagement:/dbmandj
        ports:
          - "8000:8000"
        environment:
          - POSTGRES_HOST=*******
          - POSTGRES_NAME=*******
          - POSTGRES_USER=*******
          - POSTGRES_PASSWORD=*******

Thank you for your help

  • #0 share us the docker-composer.yml #1 You don't have a **docker compose application**, you have a composer yml which start several docker containers. #2 Do you want to upload the just one of the images used in your docker-compose.yml ? – JRichardsz Dec 10 '21 at 19:37
  • @JRichardsz I just modified the question with the file. My idea was to create an image of multiple images, so that once I run the docker run command with the name of my image, everything goes up – Domenico Rossi Dec 11 '21 at 08:10
  • Your question should be something like this: image of images using docker compose or how package several services in one image – JRichardsz Dec 12 '21 at 02:17
  • What's your specific question about this? How to create an image of your application? How to run it with external services? – Nico Haase Dec 12 '21 at 09:03
  • @NicoHaase the specific question is: can I pack an application built with docker compose (as a group of different services) in one single image in order to run it by simply pulling the image from the hub? For example if in my docker-compose file I have two services, I want those packed in one single image that I can run like docker run myimage and every thing goes up. Is there a way of doing this? – Domenico Rossi Dec 12 '21 at 13:44
  • ` the container does not start up.` What is the error you get ? – XouDo Dec 17 '21 at 08:55

1 Answers1

3

The answer is: yes, you can but you should not

According to the Docker official docs:

It is generally recommended that you separate areas of concern by using one service per container

Also check this:

docker-compose is enough

docker-compose exist just for that: Run several services with one click (minimal configurations) and commonly in the same server.

foreground process

In order to works a docker container needs a foreground process. To understand what is this, check the following links. As a extremely summary we can said you that a foreground process is something that when you launch it using the shell, the shell is taken and you can and you cannot enter more commands. You need to press ctrl + c to kill the process and get back your shell.

The "fat" container

Anyway, if you want to join several services or process in one container (previously an image) you can do it with supervisor.

Supervisor could works a our foreground process. Basically you need to register one or many linux processes and then, supervisor will start them.

how to install supervisor
sudo apt-get install supervisor

source: https://gist.github.com/hezhao/bb0bee800531b89d7be1#file-supervisor_cmd-sh

add single config: /etc/supervisor/conf.d/myapp.conf
[program:myapp]
autostart = true
autorestart = true
command = python /home/pi/myapp.py
environment=SECRET_ID="secret_id",SECRET_KEY="secret_key_avoiding_%_chars"
stdout_logfile = /home/pi/stdout.log
stderr_logfile = /home/pi/stderr.log
startretries = 3
user = pi

source: https://gist.github.com/hezhao/bb0bee800531b89d7be1

start it
sudo supervisorctl start myapp
sudo supervisorctl tail myapp
sudo supervisorctl status

In the previous sample, we are used supervisor to start a python process.

multiple process with supervisor

You just need to add more [program] sections to the config file:

[program:php7.2]
command=/usr/sbin/php-fpm7.2-zts
process_name=%(program_name)s
autostart=true
autorestart=true

[program:dropbox]
process_name=%(program_name)s
command=/app/.dropbox-dist/dropboxd
autostart=true
autorestart=true

Here some examples, just like your requirement: several process in one container:

Also you could configure a web dashboard:

Another samples with docker + supervisor:

JRichardsz
  • 14,356
  • 6
  • 59
  • 94