I am having problems with docker-compose getting php-fpm container up with composer install.
I have folder structure like:
docker-compose.yml
containers/
nginx
Dockerfile
php-fpm
Dockerfile
docker-compose.yml:
version: '3'
services:
nginx:
build:
context: ./containers/nginx
ports:
- 80:80
php-fpm:
build:
context: ./containers/php-fpm
tty: true
and in php-fpm/Dockerfile:
FROM php:7.1.5-fpm-alpine
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /srv/www
ENTRYPOINT composer install --prefer-source --no-interaction --no-autoloader
With current ENTRYPOINT, it seems that composer install gets stuck at "Generating autoload files", because nothing after that is outputted and container does not appear in docker ps list.
How can I keep above folder structure, but still able to run composer install after build or run (in this case I would need to add if conditions)?
The problem is that you need a composer.json.
Please, follow these steps:
Go to Get composer web -> getting started and create a composer.json file.
Put this composer.json file in your dir structure as follows, for example:
docker-compose.yml
containers/
nginx
Dockerfile
php-fpm
Dockerfile
composer/
composer.json
Mount volume (modifying your docker-compose.yml file) to share composer.json to /var/www/html in php-fpm docker, because although you specify /srv/www/ as workdir, composer looks up in /var/www/html.
version: '3'
services:
nginx:
build:
context: ./containers/nginx
ports:
- "80:80"
php-fpm:
build:
context: ./containers/php-fpm
tty: true
volumes:
- ./composer/composer.json:/var/www/html/composer.json
I hope it's useful for you.
Related
I want to build my next js project by docker tool, but I got some trouble like this:
Error: Could not find a production build in the '/var/app/.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
Dockerfile:
FROM node:16-alpine
RUN mkdir -p /var/app
COPY ["./", "/var/app"]
WORKDIR /var/app
RUN npm i -g next
EXPOSE 3002
RUN npm run build
CMD ["npm", "run", "start"]
docker-compose.yml
version: '3.3'
services:
next-project:
container_name: next-project
build: ./
working_dir: /var/app
restart: 'unless-stopped'
volumes:
- ./:/var/app
env_file:
- .env
ports:
- "54000:3002"
I do run commands like this
docker-compose build && docker-compose up -d
the build was successful but when it run is failed, is there any missing configuration?
When you map your current directory to /var/app, all the files that are in that directory in the container become hidden and replaced with the files in the current directory.
Since you don't have a .next directory in the host directory, the container can't find the built files.
To get it to run, you need to remove the mapping of the current directory, so your docker-compose file becomes
version: '3.3'
services:
next-project:
container_name: next-project
build: ./
working_dir: /var/app
restart: 'unless-stopped'
env_file:
- .env
ports:
- "54000:3002"
I am new in docker. I've built an application with VueJs2 that interacts with an external API. I would like to run the application on docker.
Here is my docker-compose.yml file
version: '3'
services:
ew_cp:
image: vuejs_img
container_name: ew_cp
build:
context: .
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- '8080:8080'
Here is my Dockerfile:
FROM node:14.17.0-alpine as develop-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
RUN yarn install
COPY . .
EXPOSE 8080
CMD ["node"]
Here is the building command I run to build my image an container.
docker-compose up -d
The image and container is building without error but when I run the container it stops immediately. So the container is not running.
Are the DockerFile and compose files set correctly?
First of all you run npm install and yarn install, which is doing the same thing, just using different package managers. Secondly you are using CMD ["node"] which does not start your vue application, so there is no job running and docker is shutting down.
For vue applicaton you normally want to build the app with static assets and then run a simple http server to serve the static content.
FROM node:lts-alpine
# install simple http server for serving static content
RUN npm install -g http-server
# make the 'app' folder the current working directory
WORKDIR /app
# copy 'package.json' to install dependencies
COPY package*.json ./
# install dependencies
RUN npm install
# copy files and folders to the current working directory (i.e. 'app' folder)
COPY . .
# build app for production with minification
RUN npm run build
EXPOSE 8080
CMD [ "http-server", "dist" ]
Your docker-compose file could be as simple as
version: "3.7"
services:
vue-app:
build:
context: .
dockerfile: Dockerfile
container_name: vue-app
restart: always
ports:
- "8080:8080"
networks:
- vue-network
networks:
vue-network:
driver: bridge
to run the service from docker-compose use command property in you docker-compose.yml.
services:
vue-app:
command: >
sh -c "yarn serve"
I'm not sure about the problem but by using command: tail -f /dev/null in your docker-compose file , it will keep up your container so you could track the error within it and find its problem. You could do that by running docker exec -it <CONTAINER-NAME> bash and track the error logs in your container.
version: '3'
services:
ew_cp:
image: vuejs_img
container_name: ew_cp
build:
context: .
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
command: tail -f /dev/null
ports:
- '8080:8080'
In your Dockerfile you have to start your application e.g. npm run start or any other scripts that you are using for running your application in your package.json.
FROM node:latest
WORKDIR /frontend/
ENV PATH /frontend/node_modules/.bin:$PATH
COPY package.json /frontend/package.json
COPY . /frontend/
RUN npm install --silent
RUN npm install react-scripts#3.0.1 -g --silent
CMD ["npm", "run", "start"]
This is my Dockerfile for the frontend of my project.
I put this as one of the services in my docker-compose.yml file, and when I run docker-compose up -d --build, it gives me
Step 6/8 : RUN npm install --silent
---> Running in 09a4f59a96fa
ERROR: Service 'frontend' failed to build: The command '/bin/sh -c npm install --silent' returned a non-zero code: 1
My docker-compose file looks like below for your reference:
# Docker Compose
version: '3.7'
services:
frontend:
container_name: frontend
build:
context: frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- '.:/frontend'
- '/frontend/node_modules'
backend:
build: ./backend
ports:
- "5000:5000"
volumes:
- .:/code
Thanks in advance
EDIT: Error in the frontend after build
For docker-compose, I think it should be like
- ./frontend/:/frontend'
as the build context is frontend.
Second, thing if you are using volume then why you are installing and copying code in Dockerfile? If you are using bind volume then remove these from your Dockerfile as these will be overridden from the host code.
COPY package.json /frontend/package.json
COPY . /frontend/
docker-compose up --build becomes very slow using cloud docker-machine and after one hour i have and error of a not found entrypoint.sh file.
On local Mac docker-machine same config work fine.
My docker file
FROM python:3.5.2
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD app/ /code/
ADD static/ /code/
ADD entrypoint.sh /code/
my docker compose
version: '3.7'
services:
web:
build: .
command: gunicorn --bind 0.0.0.0:8000 app.wsgi
volumes:
- .:/code
entrypoint: ./entrypoint.sh
expose:
- "80"
nginx:
image: nginx:1.15.5
restart: always
ports:
- "80:80"
volumes:
- ./static:/static
depends_on:
- web
commands I run
cd myprojectfolder
eval $(docker-machine env [my-cloud-machine-name])
docker-compose -f docker-compose.yml -f envs/prd/prd.yml up --build -d
error i have after one hour (my project files are only 40mb)
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./entrypoint.sh\": stat ./entrypoint.sh: no such file or directory": unknown
ERROR: compose.cli.main.main: Encountered errors while bringing up the project.
Please help me
Thanks
I changed as suggested to this configuration but nothing changed. I'm stuck on this:
docker.api.build._set_auth_headers: Sending auth config ()
this is my new config
docker compose
version: '3.7'
services:
web:
command: gunicorn --bind 0.0.0.0:8000 app.wsgi
entrypoint: ./entrypoint.sh
expose:
- "80"
nginx:
image: nginx:1.15.5
restart: always
ports:
- "80:80"
volumes:
- ./static:/static
depends_on:
- web
my prd.yml file
version: '3.7'
services:
web:
build:
context: .
dockerfile: ./envs/prd/Dockerfile
nginx:
volumes:
- ./envs/prd/nginx/nginx.conf /etc/nginx/nginx.conf
my prd dockerfile
FROM python:3.5.2
ENV PYTHONUNBUFFERED 1
WORKDIR /
ADD requirements.txt .
RUN pip install -r requirements.txt
ADD app/ ./app
ADD static/ ./static
ADD envs/prd/settings.py /app/settings.py
ADD entrypoint.sh .
my .dockerignore
.DS_Store
.dockerignore
.git/
.gitignore
README.rst
README.md
*.pyc
__pycache__
.idea/*
Remove the volume declarations from your docker-compose and instead copy all relevant files in during the build stage (in your Dockerfile). For example in your web service remove volumes: .:/code and add COPY * /code to its Dockerfile.
I am trying to get webpack setup on my docker container. It is working, and running, but when I save on my local computer it is not updating my files in my container. I have the following docker-compose file:
version: '2'
services:
web:
build:
context: .
dockerfile: docker/web/Dockerfile
container_name: arc-bis-www-web
restart: on-failure:3
environment:
FPM_HOST: 'php'
ports:
- 8080:8080
volumes:
- ./app:/usr/local/src/app
php:
build:
context: .
dockerfile: docker/php/Dockerfile
environment:
CRM_HOST: '192.168.1.79'
CRM_NAME: 'ARC_test_8_8_17'
CRM_PORT: '1433'
CRM_USER: 'sa'
CRM_PASSWORD: 'Multi*Gr4in'
volumes:
- ./app:/usr/local/src/app
node:
build:
context: .
dockerfile: docker/node/Dockerfile
container_name: arc-bis-www-node
volumes:
- ./app:/usr/local/src/app
and my node container is run by the following dockerfile:
FROM node:8
RUN useradd --create-home user
RUN mkdir /usr/local/src/app
RUN mkdir /usr/local/src/app/src
RUN mkdir /usr/local/src/app/test
WORKDIR /usr/local/src/app
# Copy application source files
COPY ./app/package.json /usr/local/src/app/package.json
COPY ./app/.babelrc /usr/local/src/app/.babelrc
COPY ./app/webpack.config.js /usr/local/src/app/webpack.config.js
COPY ./app/test /usr/local/src/app/test
RUN chown -R user:user /usr/local/src/app
USER user
RUN npm install
ENTRYPOINT ["npm"]
Now I have taken out the copy calls from above and it still runs fine, but neither option is allowing me to save files locally and have them show up in the localhost for my container. Ideally, I thought having a volume would allow me to update my local files and have it read by the volume in the container. Does that make sense? I am still feeling my way around Docker. Thanks in advance for any help.
If you start your container with -v tag, you can map the container and your local storage. You can find more information here.