I'm trying to run uwsgi, and it works fine if I run with docker run -d foo but fails if I do docker-compose up with error
bind(): Permission denied [core/socket.c line 230]
docker-compose.yml
services:
web:
restart: always
build:
context: .
dockerfile: ./compose/production/web/Dockerfile
image: foo
volumes:
- /app
- /var/log
Dockerfile
....
CMD uwsgi --uid www-data --gid www-data --emperor /app/momsite/momsite/conf/docker/etc/uwsgi/vassals
Related
Even though I'm setting the proper permissions in a Dockerfile, docker-compose up throws an error:
Attaching to lab-track-raport-app-db-1, lab-track-raport-app-web-1
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./docker-entrypoint.sh": permission denied: unknown
My Dockerfile:
# syntax=docker/dockerfile:1
FROM python:3.9
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Set workdir
WORKDIR /code
# Copy project files
COPY . /code/
# Install dependencies
# RUN pip install -r requirements.txt
# Add permissions for the entrypoint file
RUN chmod +x "./docker-entrypoint.sh"
# debug
RUN ls -la .
# maybe it's overwritten when mounting volume? set permissions again
CMD ["chmod", "+x", "./docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]
docker-compose.yml:
version: "3.9"
services:
db:
image: mysql/mysql-server:latest
environment:
- MYSQL_DATABASE=mariadb
- MYSQL_USER=mariadb
- MYSQL_PASSWORD=mariadb
- MYSQL_PORT=3306
ports:
- 3306:3306
expose:
- 3306
web:
build: .
volumes:
- .:/code
ports:
- "8000:8000"
environment:
- MYSQL_DATABASE=mariadb
- MYSQL_USER=mariadb
- MYSQL_PASSWORD=mariadb
- MYSQL_PORT=3306
depends_on:
- db
docker-entrypoint.sh
#!/bin/bash
echo "Waiting"
./wait-for-it.sh "db:3306"
echo "Apply database migrations"
python manage.py migrate
echo "Seed database"
python manage.py loaddata seed.json
echo "Running the app"
python manage.py runserver 0.0.0.0:8000
You copy your code into the /code directory, but then at runtime you also map your current directory onto /code which then 'hides' the /code directory in the image and replaces it with the current directory from your host machine.
Remove the volume mapping, so the container can use the /code directory in the image
web:
build: .
ports:
- "8000:8000"
environment:
- MYSQL_DATABASE=mariadb
- MYSQL_USER=mariadb
- MYSQL_PASSWORD=mariadb
- MYSQL_PORT=3306
depends_on:
- db
I'm building a PHP 7.4 container from Dockerfile but i have a little problem with groupadd and rights.
The error message on build with docker-compose build --no-cache :
Step 41/46 : RUN groupadd -g ${SITE_GID} www
---> Running in ee94c83629f7
groupadd: invalid group ID 'www'
ERROR: Service 'php' failed to build: The command '/bin/sh -c groupadd -g ${SITE_GID} www' returned a non-zero code: 3
Here's my docker-compose with PHP container :
services:
# PHP
php:
build:
context: docker/php7-fpm
args:
TIMEZONE: ${TIMEZONE}
SITE_UID: ${SITE_UID}
SITE_GID: ${SITE_GID}
user: ${SITE_UID:-1000}:${SITE_GID:-1000}
restart: unless-stopped
hostname: php
volumes:
- ".:/var/www/symfony:rw"
- "./docker/php7-fpm/pool.d/application.conf:/opt/docker/etc/php/fpm/pool.d/application.conf"
- "./docker/php7-fpm/www.conf:/usr/local/etc/php-fpm.d/www.conf"
- "$SSH_AUTH_SOCK:/ssh-agent:ro"
env_file:
- ".env"
environment:
- SSH_AUTH_SOCK=/ssh-agent
working_dir: /var/www/symfony
networks:
- dso_stack
Variables ${SITE_UID} and ${SITE_GID} are defined in .env file :
SITE_UID=XXXX # from command id -u
SITE_GID=YYYY # from command id -g
And my Dockerfile :
ARG PHP_VERSION=7.4
ARG TIMEZONE
ARG SITE_UID
ARG SITE_GID
FROM php:${PHP_VERSION}-fpm
USER root
# Installation of all dependencies..
# Add user for Symfony application
RUN groupadd -g ${SITE_GID} www
RUN useradd -u ${SITE_UID} -ms /bin/bash -g www www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www/symfony
USER www
EXPOSE 9000
CMD ["php-fpm"]
I'm not a docker jedi ^^ so i'm sure there are many little errors but i don't find exactly where. Thank you for answers :)
with below command, docker-compose up --build, although image is generated but when container is started, it throws an error as follows,
Starting da3e68163f87_khatabook-app ... done
Attaching to da3e68163f87_khatabook-app
da3e68163f87_khatabook-app | /bin/sh: ./gradlew: not found
da3e68163f87_khatabook-app exited with code 127
And whole log, screenshot as an attachment.
Below is my Dockerfile as follows,
FROM openjdk:8-jdk-alpine
RUN apk add --no-cache bash
WORKDIR /Khatabook\ Account
CMD ./gradlew run
docker-compose.yml is as follows,
version: "3.6"
services:
app:
build: ./
container_name: khatabook-app
volumes:
- ./:/Khatabook\ Account
ports:
- 8080:8080
expose:
- 8080
I had tried to use,
CMD chmod +x ./gradlew run
but didn't worked
My Source code root folder name is,
Khatabook Account
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.
Here is my docker-compose.yml:
version: '3.3'
services:
etcd:
container_name: 'etcd'
image: 'quay.io/coreos/etcd'
command: >
etcd -name etcd
-advertise-client-urls http://127.0.0.1:2379,http://127.0.0.1:4001
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
-initial-advertise-peer-urls http://127.0.0.1:2380
-listen-peer-urls http://0.0.0.0:2380
healthcheck:
test: ["CMD", "curl", "-f", "http://etcd:2379/version"]
interval: 30s
timeout: 10s
retries: 5
networks:
robotrader:
kontrol:
container_name: 'kontrol'
env_file: 'variables.env'
build:
context: '.'
dockerfile: 'Dockerfile'
volumes:
- '/certs:/certs'
ports:
- '6000:6000'
depends_on:
- 'etcd'
networks:
robotrader:
mongo:
container_name: 'mongo'
image: 'mongo:latest'
ports:
- '27017:27017'
volumes:
- '/var/lib/mongodb:/var/lib/mongodb'
networks:
robotrader:
networks:
robotrader:
... and here is the Dockerfile used to build kontrol:
FROM golang:1.8.3 as builder
RUN go get -u github.com/golang/dep/cmd/dep
RUN go get -d github.com/koding/kite
WORKDIR ${GOPATH}/src/github.com/koding/kite
RUN ${GOPATH}/bin/dep ensure
RUN go install ./kontrol/kontrol
RUN mv ${GOPATH}/bin/kontrol /tmp
FROM busybox
ENV APP_HOME /opt/robotrader
RUN mkdir -p ${APP_HOME}
RUN mkdir /certs
WORKDIR ${APP_HOME}
COPY --from=builder /tmp/kontrol .
ENTRYPOINT ["./kontrol", "-initial"]
CMD ["./kontrol"]
Finally when I issue the command...
sudo -E docker-compose -f docker-compose.yaml up
... both etcd and mongo start successfully, whereas kontrol fails with the following error:
kontrol | 2018/06/21 20:11:14 cannot read public key file: open "/certs/key_pub.pem": no such file or directory
If I log into the container..
sudo docker run -it --rm --name j3d-test --entrypoint sh j3d
... and look at folder /certs, the files are there:
ls -la /certs
-rw-r--r--. 1 root root 1679 Jun 21 21:11 key.pem
-rw-r--r--. 1 root root 451 Jun 21 21:11 key_pub.pem
What am I missing?
When you run this command:
sudo docker run -it --rm --name j3d-test --entrypoint sh j3d
You are not "logging into the container". You are creating a new container, and you are looking at the contents of /certs on the underlying image. However, in your docker-compose.yaml you have:
kontrol:
[...]
volumes:
- '/certs:/certs'
[...]
You have configured a bind mount from $PWD/certs onto the /certs
directory in your container. What does your local certs directory
contain?