How to run php-fpm in docker-compose.yml? - docker

I tried to build a container used docker-compose. So I wrote the dockerfile and docker-compose.yml like following:
dockerfile
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y expect
RUN apt-get -y install software-properties-common
RUN apt-add-repository ppa:ondrej/php
RUN apt-get -y install php7.1 php7.1-fpm
RUN apt-get install php7.1-mysql
RUN apt-get -y install nginx
RUN apt-get -y install vim
COPY default /etc/nginx/sites-available/default
COPY www.conf /etc/php/7.1/fpm/pool.d/www.conf
COPY test /var/www/html/test
CMD service php7.1-fpm start && nginx -g "daemon off;"
docker-compose.yml
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "3011:80"
When I run following command, the php7.1-fpm is run success.
docker-compose build
docker-compose up --force-recreate -d
But I want to move the CMD from dockerfile to docker-compose, so I changed the file like following:
docker-compose.yml
command: service php7.1-fpm start && nginx -g "daemon off;"
But this time php7.1-fpm is not running.
How to fix this issue, so that I can run php7.1-fpm in docker-compose.yml?

you can not use service php7.1-fpm start in your Dockerfile, because container is just a process, not a real virtual machine, main process down and others will down neither
docker suggest you to divide them in different container, php-fpm, nginx, single image single container
solution:
docker/php-fpm/Dockerfile
FROM php:7.2-fpm
RUN docker-php-ext-install pdo pdo_mysql mbstring
docker-compose.yml:
version: '2.1'
services:
nginx:
image: nginx:latest
ports:
- 8001:80
volumes:
- ./:/app
# nginx configs
- ./docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
php-fpm:
build: ./docker/php-fpm
volumes:
- ./:/app
php-composer:
restart: 'no'
image: composer
volumes:
- ./:/app
command: install
nodejs:
restart: 'no'
image: node:8.9
volumes:
- ./:/app
command: /bin/bash -c "cd /app && npm install && npm run prod"
networks:
default:

Related

Access docker app outside container using docker-compose

I'm running docker-compose to run my application which listen to REST api calls.
For some reason it is not accessible from outside.
I don't understand what am I doing wrong.
Here is the configuration:
version: '3.4'
services:
rabbitmq:
image: rabbitmq:3-management
ports:
- 5672:5672
- 15672:15672
my-server:
image: my-server
build:
context: .
dockerfile: ./apiserver/Dockerfile
ports:
- 5000:5000
restart: on-failure
depends_on:
- rabbitmq
and my Dockerfile is:
FROM ubuntu:16.04
RUN apt-get update -y && \
apt-get install -y python-pip python-dev
# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
EXPOSE 5000
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]

New code changes exist in live container but are not reflected in the browser

I am using Docker with the open source BI tool Apache Superset. I have added a new file, specifically a .geojson file in the CountryMap directory. Now, when I try to build using docker-compose up --build or make changes in the frontend, Docker is not fully updated, and I get a file not found error when trying to run a query. When I look inside the container via docker exec -it container_id bash, the new file is there.
Dockerfile:
FROM python:3.6-jessie
RUN useradd --user-group --create-home --no-log-init --shell /bin/bash superset
# Configure environment
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8
RUN apt-get update -y
# Install dependencies to fix `curl https support error` and `elaying package configuration warning`
RUN apt-get install -y apt-transport-https apt-utils
# Install superset dependencies
# https://superset.incubator.apache.org/installation.html#os-dependencies
RUN apt-get install -y build-essential libssl-dev \
libffi-dev python3-dev libsasl2-dev libldap2-dev libxi-dev
# Install extra useful tool for development
RUN apt-get install -y vim less postgresql-client redis-tools
# Install nodejs for custom build
# https://superset.incubator.apache.org/installation.html#making-your-own-build
# https://nodejs.org/en/download/package-manager/
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt-get install -y nodejs
WORKDIR /home/superset
COPY requirements.txt .
COPY requirements-dev.txt .
COPY contrib/docker/requirements-extra.txt .
RUN pip install --upgrade setuptools pip \
&& pip install -r requirements.txt -r requirements-dev.txt -r requirements-extra.txt \
&& rm -rf /root/.cache/pip
RUN pip install gevent
COPY --chown=superset:superset superset superset
ENV PATH=/home/superset/superset/bin:$PATH \
PYTHONPATH=/home/superset/superset/:$PYTHONPATH
USER superset
RUN cd superset/assets \
&& npm ci \
&& npm run build \
&& rm -rf node_modules
COPY contrib/docker/docker-init.sh .
COPY contrib/docker/docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
HEALTHCHECK CMD ["curl", "-f", "http://localhost:8088/health"]
EXPOSE 8088
docker-compose.yml:
version: '2'
services:
redis:
image: redis:3.2
restart: unless-stopped
ports:
- "127.0.0.1:6379:6379"
volumes:
- redis:/data
postgres:
image: postgres:10
restart: unless-stopped
environment:
POSTGRES_DB: superset
POSTGRES_PASSWORD: superset
POSTGRES_USER: superset
ports:
- "127.0.0.1:5432:5432"
volumes:
- postgres:/var/lib/postgresql/data
superset:
build:
context: ../../
dockerfile: contrib/docker/Dockerfile
restart: unless-stopped
environment:
POSTGRES_DB: superset
POSTGRES_USER: superset
POSTGRES_PASSWORD: superset
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
REDIS_HOST: redis
REDIS_PORT: 6379
# If using production, comment development volume below
#SUPERSET_ENV: production
SUPERSET_ENV: development
# PYTHONUNBUFFERED: 1
user: root:root
ports:
- 8088:8088
depends_on:
- postgres
- redis
volumes:
# this is needed to communicate with the postgres and redis services
- ./superset_config.py:/home/superset/superset/superset_config.py
# this is needed for development, remove with SUPERSET_ENV=production
- ../../superset:/home/superset/superset
volumes:
postgres:
external: false
redis:
external: false
Why is there a not found error?
try to use absolute path in volumes:
volumes:
- /home/me/my_project/superset_config.py:/home/superset/superset/superset_config.py
- /home/me/my_project/superset:/home/superset/superset
It is because docker-compose is utilizing cache. If the dockerfile and the docker-compose.yml in not changed it does not recreate the container image. To avoid this you should use the following flag:
--force-recreate
--force-recreate
Recreate containers even if their configuration and image haven't
changed.
For development purposes I like to use the following switch as well:
-V, --renew-anon-volumes
Recreate anonymous volumes instead of retrieving data from the previous containers.

How to define a docker cli service in docker-compose

I have a docker-compose file that runs a few services.
services:
cli:
build:
context: .
dockerfile: docker/cli/Dockerfile
volumes:
- ./drupal8site:/var/www/html/drupal8site
drupal:
container_name: drupal
build:
context: .
dockerfile: docker/DockerFile.drupal
args:
DOC_ROOT: /var/www/html/drupal8site
ports:
- 80:80
volumes:
- ./drupal8site:/var/www/html/drupal8site
restart: always
environment:
APACHE_DOCUMENT_ROOT: /var/www/html/drupal8site/web
mysql:
image: mysql:5.7
ports:
- 3306:3306
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
I would like to add another service which will be a container in which I could run CLI commands (composer, drush for drupal, php, etc).
The following Dockerfile was how I initially defined the cli service but it stops right after it is run. How do I define it so it is part of my docker-compose, shares my mounted volume, and I can interactively connect to it and run CLI commands on it ?
FROM php:7.2-cli
#various programs
RUN apt-get update \
&& apt-get install vim --assume-yes \
&& apt-get install git --assume-yes \
&& apt-get install mysql-client --assume-yes
CMD ["bash"]
Thanks,
Yaron
If you want to run automated scripts on docker images this is obviously a job for a ci-pipeline. You can use CloudFoundry or OpenStack to do this.
But there are many other questions in this post:
1.) How can i share my mounted volume:
You can pass a volume with the -v option to a container. e.g.:
docker run -it -d -v $(pwd)/localFolder:/exposedFolderFromDocker mydockerhub/myawesomeimage
2.) Can I interactively connect to it and run CLI commands on it
docker exec -it docker_cli_1 bash
I recommend to implement features of an docker-image to the individual docker-images Dockerfile. For example copying and running a prepared shell-script:
# your Dockerfile
FROM php:7.2-cli
#various programs
RUN apt-get update \
&& apt-get install vim --assume-yes \
&& apt-get install git --assume-yes \
&& apt-get install mysql-client --assume-yes
# individual changes
COPY your_script.sh /
RUN chown root:root /your_script.sh && \
chmod 0755 /your_script.sh
CMD ["/your_script.sh"]
# a folder to expose
VOLUME /exposedFolderFromDocker
CMD ["bash"]

Problem with create Dockercompose and Dockerfile. Causes "Error response from daemon"

This is my first dockerfile project with docker-compose. In my project I try create a docker-compose file.
node/Dockerfile
FROM centos:latest
MAINTAINER braulio#braulioti.com.br
LABEL Description="Site Brau.io - API NodeJS"
EXPOSE 3000
RUN yum update -y \
&& yum install -y java-1.8.0-openjdk \
&& yum update -y \
&& yum install -y epel-release \
&& yum install -y nodejs \
&& yum install -y psmisc \
&& npm install -g forever \
&& npm install -g typescript
RUN rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Brazil/East /etc/localtime
RUN mkdir -p /app
VOLUME ["/app"]
docker-compose.yml
version: '3'
services:
node:
build: node
image: docker_node
ports:
- "8082:3000"
container_name: "brau_io_api"
volumes:
- /app/brau_io/api:/app/
command: /bin/bash
This project result in:
Error response from daemon: Container 65cecc8bdc923c3f596dba91fd059b8268fd390737391d4d91afa7d34325bea1 is not running
In docker-compose you should create some services and you can link them. for example:
docker-compose.yml
version: '3'
services:
my_app:
build: .
image: my_app:1.0.0
container_name: my_app_container
command: ... # you can run a bash file or a command
I created a docker-compose with my_app service which it can create my_app image.
you can rewrite it with your node container.
Reference
I enabled the tty function in my docker-compose.yml file and works like a chaming (See Reference).
This is my final docker-compose.yml file:
docker-compose.yml
version: '3'
services:
node:
build: node
image: docker_node
ports:
- "8082:3000"
container_name: "brau_io_api"
volumes:
- /app/brau_io/api:/app/
command: /bin/bash
tty: true

How to add GDAL in docker

I am trying to setup Docker and geodjagno. Upon docker-compose up I have this following error:
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0", "gdal1.10.0", "gdal1.9.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
GDAL is a library that can be found in this image wooyek/geodjango
Dockerfile
FROM wooyek/geodjango
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
docker-compose
services:
web:
build: .
container_name: web
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
db:
image: mdillon/postgis
#command: -e POSTGRES_USER=johndoe -e POSTGRES_PASSWORD=myfakedata -e POSTGRES_DB=myfakedata library/postgres
environment:
- POSTGRES_USER=johndoe
- POSTGRES_PASSWORD=myfakedata
- POSTGRES_DB=myfakedata
ports:
- "5435:5432"
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Try adding the following in your Dockerfile:
RUN apt-get update &&\
apt-get install -y binutils libproj-dev gdal-bin
You can add the following to your docker file
# Install GDAL dependencies
RUN apt-get install -y libgdal-dev g++ --no-install-recommends && \
apt-get clean -y
# Update C env vars so compiler can find gdal
ENV CPLUS_INCLUDE_PATH=/usr/include/gdal
ENV C_INCLUDE_PATH=/usr/include/gdal

Resources