2

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

1
  • Hello, did you resolve your issue? Commented Oct 18, 2016 at 12:11

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

9 Comments

I believe that use my built image wont work since that image will have the parameters setup for my local PC and wont work for others. I am right?
It just depends on your Dockerfile and how you are using your environment variables. In fact in rare cases the env variables values are used to build the image. I can't find your github repo in docker hub. You can post here to have a look
Here is the repo in DockerHub and here is in Github let me know your thoughs on this
In fact the environment variables are used in entrypoint so they won't get into the image. The args PUID and PGID are part of the build process. Why you need to specify those values to create the docker user? For host mounted volumes? Think there should be a workaround
I am not using them for anything right now. What do you mean with should be a workaround?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.