Docker-compose linking service into dockerfile

I am pretty new to docker, and I am trying to make a container with multiple apps.

Let say that my docker-compose file is like this :

  • Getting 502 Bad Gateway while running the Django application within a docker container?
  • How to do host-specific customization on docker images
  • How can I connect to MongoDB on a Dokku host?
  • How to deploy webapp or war file in tomcat that is running in docker container
  • Error while running portia on docker in ubuntu
  • Docker container behind virtual router
  • version: '2'
    
    services:
        myapp:
            build: ./dockerfiles/myapp
            volumes:
              - ./www:/var/www
              - ./logs:/var/log
              - ./mysql-data:/var/lib/mysql
              - ./php:/etc/php5
              - ./nginx:/etc/nginx
            ports:
                - "8082:8000"
                - "6606:3306"
            links:
                - mysql:mysql
                - php:php
                - nginx:nginx
        mysql:
            image: mysql
            environment:
                MYSQL_ROOT_PASSWORD: M@yW3Bw35t
                MYSQL_USER: replymwp
                MYSQL_PASSWORD: ZSzLPoOi9wlhFaiJ
        php:
            image: php:5.6-fpm
            links:
                - mysql:db
        nginx:
            image: nginx
            links:
                - php:php
    

    Now, in myapp DockerFile, I want to install a package that needs mysql.

    FROM debian:jessie
    
    RUN apt-get update
    
    RUN apt-get update 
    RUN apt-get install -y apt-show-versions
    
    RUN apt-get install -y wget 
    RUN wget http://repo.ajenti.org/debian/key -O- | apt-key add -
    RUN echo "deb http://repo.ajenti.org/ng/debian main main ubuntu" >>         /etc/apt/sources.list
    RUN apt-get update 
    RUN apt-get install -y ajenti
    
    RUN apt-get install -y ajenti-v ajenti-v-ftp-vsftpd ajenti-v-php-fpm ajenti-v-mysql
    
    EXPOSE 8000
    ENTRYPOINT ["ajenti-panel"]
    

    Now the problem is, when docker try to build my image, it install php, mysql etc… even if I link it in my docker-compose file. And secondly, when it try to install mysql, It prompt for a master password and stay blocked at this step, even if I fill something…

    Maybe am I totally wrong in my way of using it?

    Any help would be appreciate.

  • How could I launch multiple container at a time shared one Dockerfile
  • docker-compose up fails with “UnixHTTPConnectionPool(host='localhost', port=None): Pool is closed”
  • Azure - creating FQDN from a script
  • docker-compose: how to map few ip to few containers
  • add entry to host /etc/hosts file when a docker container is started
  • how to define HTTP health check in a consul container for a service on the same host?
  • 2 Solutions collect form web for “Docker-compose linking service into dockerfile”

    I suppose your ajenti has a dependency on mysql, so if you do apt-get install ajenti, it tries to satisfy that dependency. Specifically you are installing ajenti-v-mysql, which does seem to have a mysql dependency

    Because you want to run mysql seperate, you might need to do --no-install-recommends ? This is a flag voor apt-get, so you’d get something like

    apt-get install <packagename> --no-install-recommends
    

    This would mean you get NO dependencies, so you might need to figure out which other depenencies you need.

    The php-fpm has the same issue, I suppose that whole line which includes ajenti-v-php-fpm is a bit too much?

    If you’re planning on using separate mysql and php containers, then why are you still including the installation in the mpapp dockerfile on this line:

    RUN apt-get install -y ajenti-v ajenti-v-ftp-vsftpd ajenti-v-php-fpm ajenti-v-mysql

    If you’re going to use mysql and php containers then you don’t need them in your app. This should also take care of your second problem about being prompted for mysql password.

    Keep in mind that you will need to change the hostnames of mysql and your php configuration from your myapp configuration. I think you might be better off looking for a tutorial for setting up docker compose, you’ll have to look yourself to find the most suitable but something like this would give you a good start.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.