简体   繁体   中英

Building and uploading images to Docker Hub, how to from Docker Compose?

I have been working in a docker environment for PHP development and finally I get it working as I need. This environment relies on docker-compose and the config looks like:

version: '2'
services:
    php-apache:
        env_file:
          - dev_variables.env
        image: reynierpm/php55-dev
        build:
            context: .
            args:
                - PUID=1000
                - PGID=1000
        ports:
            - "80:80"
        extra_hosts:
            - "dockerhost:xxx.xxx.xxx.xxx"
        volumes:
            - ~/var/www:/var/www

There are some configurations like extra_hosts and env-file that is giving me some headache. Why? Because I don't know if the image will works under such circumstances.

Let's said:

  • I have run docker-compose up -d and the image reynierpm/php55-dev with tag latest has been built
  • I have everything working as it should be because I am setting the proper values on the docker-compose.yml file
  • I have logged in into my account and I push the image to the repository: docker push reynierpm/php55-dev

What happen if tomorrow you clone the repository and try to run docker-compose up but changing the docker-compose.yml file to fit your settings? How the image behaves in this case? I mean makes sense to create/upload the image to Docker Hub if any time I run the command docker-compose up it will be build again due to the changes on the config file?

Maybe I am completing wrong and some magic happen behind scenes but I need to know if I am doing this right

If people clone your git repository and do a docker-compose up -d it will in fact building a new image. If you only want people use your image from docker hub, drop the build section of docker-compose.yml and publish it in your docker hub page. Check this you can see the proposed docker-compose.yml.

Just paste this in your page:

version: '2'
services:
  php-apache:
    image: reynierpm/php55-dev
    ports:
      - "80:80"
    environment:
      DOCKERHOST: 'yourhostip'
      PHP_ERROR_REPORTING: 'E_ALL & ~E_DEPRECATED & ~E_NOTICE'
    volumes:
      - ~/var/www:/var/www

If your env_file just have a couple of variables it is better to show them directly in the Dockerfile. It is better to replace extra_hosts with an environment variable and change in your php.ini or where ever you use the extra host by the variable:

.....
xdebug.remote_host         = ${DOCKERHOST}
.....

You can in your Dockerfile define a default value for this variable:

ENV DOCKERHOST=localhost

Hope it helps

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM