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 :
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.
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.
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.