Why the volume folder is empty after a redis save? - docker

Code
I'm trying to run a redis service defined inside a docker-compose.yml as follows:
version: '3'
services:
redis:
image: "redis:5-alpine"
volumes:
- ./redis-vol:/home/data
app:
build: .
ports:
- 8080:8080
volumes:
- .:/home/app/
This is the Dockerfile:
FROM python:2.7-alpine3.8
WORKDIR /home/app
COPY ./requirements.txt .
RUN apk add python2-dev build-base linux-headers pcre-dev && \
pip install -r requirements.txt
# Source files
COPY ./api.py .
COPY ./conf.ini .
CMD ["uwsgi", "--ini", "conf.ini"]
The app consists of this snippet running a uwsgi interface on port 8080
import uwsgi
import redis
r = redis.Redis('redis')
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
r.append('hello', 'world!')
r.save()
return [b"Hello World"]
And this is the conf.ini file:
[uwsgi]
http = :8080
wsgi-file = api.py
master = true
process = 2
enable-threads = true
uid = 1001
gid = 1001
The app service is supposed to save a key:value pair through redis every time it receives a request to http://localhost:8080.
Upon a successful request, the docker-compose process returns the following log:
redis_1_bdf757fbb2bf | 1:M 26 Nov 2018 15:38:20.399 * DB saved on disk
app_1_5f729e6bcd36 | [pid: 17|app: 0|req: 1/1] 172.21.0.1 () {38 vars in 690 bytes} [Mon Nov 26 15:38:20 2018] GET / => generated 11 bytes in 8 msecs (HTTP/1.1 200) 1 headers in 44 bytes (1 switches on core 0)
redis_1_bdf757fbb2bf | 1:M 26 Nov 2018 15:38:20.998 * DB saved on disk
app_1_5f729e6bcd36 | [pid: 17|app: 0|req: 2/2] 172.21.0.1 () {40 vars in 691 bytes} [Mon Nov 26 15:38:20 2018] GET /favicon.ico => generated 11 bytes in 4 msecs (HTTP/1.1 200) 1 headers in 44 bytes (1 switches on core 0)
Problem
Despite the DB saved on disk log, the redis_vol folder is empty and the dump.rdb file doesn't seem to be saved anywhere else.
What I am doing wrong? I've also tried to use redis:alpine as image but I have the following error at startup:
redis_1_bdf757fbb2bf | 1:M 26 Nov 14:57:27.003 # Can't handle RDB format version 9
redis_1_bdf757fbb2bf | 1:M 26 Nov 14:57:27.003 # Fatal error loading the DB: Invalid argument. Exiting.
And I've also tried to map the dump.rdb in the redis service as follows:
redis:
image: "redis:5-alpine"
volumes:
- ./redis-vol/dump.rdb:/home/data/dump.rdb
but the docker creates a folder named dump.rdb/ instead of a readable file.

If you still face the problem even after changing the volume map to
<your-volume>:/data
Make sure to delete the previous container with
docker container prune
before restarting your container again

Accoring to the redis documentation on the DockerHub page
If persistence is enabled, data is stored in the VOLUME /data
So you are using the wrong volume path. Yout should use /data instead
volumes:
- ./redis-vol:/data

To be able to mount a single file for your container with docker-compose, use absolute path of the file you want to mount from your filesystem:
redis:
image: "redis:5-alpine"
volumes:
- /Users/username/dirname/redis-vol/dump.rdb:/home/data/dump.rdb

As codestation correctly pointed out, it is on the
official documenation but he is suggesting
mount point instead of volumes which has some additional cons.
In both cases in documentation there is also statement about "persistence
enabled":
$ docker run --name some-redis -d redis redis-server --appendonly yes
or in your docker-compose file:
redis:
image: "redis:alpine"
command: redis-server --appendonly yes
volumes:
- your-volume:/data

Related

Keycloak Docker Deployment

I tried to deploy Keycloak and it's database via Docker (Docker-Compose).
It retries 10 times, then failes the deployment. The same docker-compose.yml file worked for me in the past. Haven't done any OS or contianer updates since.
The the following error and warning is thrown:
keycloak | 09:48:42,070 ERROR [org.jgroups.protocols.TCP] (ServerService Thread Pool -- 60) JGRP000034: cff2ce8f5cdf: failure sending message to e832b25e9785: java.net.SocketTimeoutException: connect timed out
keycloak | 09:48:45,378 WARN [org.jgroups.protocols.pbcast.GMS] (ServerService Thread Pool -- 60) cff2ce8f5cdf: JOIN(cff2ce8f5cdf) sent to 05bdb7a4a7f5 timed out (after 3000 ms), on try 0
My docker-compose.yml looks like this:
keycloak:
container_name: keycloak
image: jboss/keycloak:11.0.2
ports:
- 8081:8080
environment:
- DB_VENDOR=mariadb
- DB_ADDR=authenticationDB
- DB_DATABASE=keycloak
- DB_USER=keycloak
- DB_PASSWORD=password
- KEYCLOAK_USER=admin
- KEYCLOAK_PASSWORD=admin
- JGROUPS_DISCOVERY_PROTOCOL=JDBC_PING
- JGROUPS_DISCOVERY_PROPERTIES=datasource_jndi_name=java:jboss/datasources/KeycloakDS,info_writer_sleep_time=500
depends_on:
- authenticationDB
authenticationDB:
container_name: authenticationDB
image: mariadb
volumes:
- ./keycloakDB:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: keycloak
MYSQL_USER: keycloak
MYSQL_PASSWORD: password
healthcheck:
test: ["CMD", "mysqladmin", "ping", "--silent"]
I've tried following:
SSH into Keycloak's container and curl authenticationDB:3306. I've got a no permission error so the container could talk to each other.
Check if the database is running inside the DB-Container and yes, it's running.
I am running out of ideas.
Normally it retried 10 times, and then successfully deployed keycloak.
Thanks in advance,
Rosario
I would say that docker image jboss/keycloak:11.0.2 doesn't support JDBC_PING:
$ docker run --rm --entrypoint bash -ti jboss/keycloak:11.0.2 \
-c 'ls -lah /opt/jboss/tools/cli/jgroups/discovery/'
total 4.0K
drwxrwxr-x. 1 jboss root 25 Sep 15 09:01 .
drwxrwxr-x. 1 jboss root 23 Sep 15 09:01 ..
-rw-rw-r--. 1 jboss root 611 Sep 15 09:01 default.cli
vs
$ docker run --rm --entrypoint bash -ti jboss/keycloak:12.0.2 \
-c 'ls -lah /opt/jboss/tools/cli/jgroups/discovery/'
total 8.0K
drwxrwxr-x. 1 jboss root 46 Jan 19 07:27 .
drwxrwxr-x. 1 jboss root 23 Jan 19 07:27 ..
-rw-rw-r--. 1 jboss root 611 Jan 19 07:27 default.cli
-rw-rw-r--. 1 jboss root 605 Jan 19 07:27 JDBC_PING.cli
Try to test newer version.

How to get Docker-Compose to run a shell command before starting IBM-MQ server?

Hey guys so I've been trying to get my docker-compose.yml file to just cat the contents of a local file before it boots up the IBM-MQ server but I can't seem to get the MQ server to work correctly. I have a simple helloworld.txt in the files folder that just consists of HELLO WORLD in it that I'm trying to cat.
version: '3'
mq:
image: ibmcom/mq:latest
ports:
- "1414:1414"
environment:
- LICENSE=accept
- MQ_QMGR_NAME=MQA01
volumes:
- ./files:/var/mqm
stdin_open: true
tty: true
restart: always
command: >
sh -c "cat helloworld.txt"
But running docker-compose up gives the below error -
mq_1 | 2019-09-11T18:15:24.360Z CPU architecture: amd64
mq_1 | 2019-09-11T18:15:24.360Z Linux kernel version: 4.15.0-20-generic
mq_1 | 2019-09-11T18:15:24.360Z Container runtime: docker
mq_1 | 2019-09-11T18:15:24.361Z Base image: Red Hat Enterprise Linux Server 7.6 (Maipo)
mq_1 | 2019-09-11T18:15:24.365Z Running as user ID 888 () with primary group 888, and supplementary groups 0
mq_1 | 2019-09-11T18:15:24.365Z Capabilities (bounding set): chown,dac_override,fowner,fsetid,kill,setgid,setuid,setpcap,net_bind_service,net_raw,sys_chroot,mknod,audit_write,setfcap
mq_1 | 2019-09-11T18:15:24.366Z seccomp enforcing mode: filtering
mq_1 | 2019-09-11T18:15:24.366Z Process security attributes: docker-default (enforce)
mq_1 | 2019-09-11T18:15:24.366Z Detected 'ext4' volume mounted to /mnt/mqm/data
mq_1 | 2019-09-11T18:15:24.467Z Set password for "admin" user
mq_1 | 2019-09-11T18:15:24.579Z Using queue manager name: MQA01
mq_1 | 2019-09-11T18:15:24.580Z Error: Unable to change ownership of /mnt/mqm/data
mq_1 | 2019-09-11T18:15:24.580Z chown /mnt/mqm/data: operation not permitted
EDIT - I changed volumes to
volumes:
- ./files/helloworld.txt:/usr/local/tomcat/webapps/helloworld.txt
But now it just seems like the manager runs indefinitely and the shell command cat helloworld.txt is never run.
Error: Unable to change ownership of /mnt/mqm/data
Running with the default configuration and a volume
The above example will not persist any configuration data or messages
across container runs. In order to do this, you need to use a volume.
For example, you can create a volume with the following command:
docker volume create qm1data
You can then run a queue manager using this volume as follows:
docker run \
--env LICENSE=accept \
--env MQ_QMGR_NAME=QM1 \
--publish 1414:1414 \
--publish 9443:9443 \
--detach \
--volume qm1data:/mnt/mqm \
ibmcom/mq
or after
docker volume create qm1data
volume once created then
image: ibmcom/mq:latest
ports:
- "1414:1414"
environment:
- LICENSE=accept
- MQ_QMGR_NAME=MQA01
volumes:
- qm1data:/var/mqm
stdin_open: true
tty: true
restart: always
The Docker image always uses /mnt/mqm for MQ data, which is correctly linked for you under /var/mqm at runtime. This is to handle problems with file permissions on some platforms.
running-with-the-default-configuration-and-a-volume

Connect to a Nest.js server inside a docker container

I'm trying to create a container for a Nest.js server. For now,I only have the basic version of the server that creates automatically when you create a Nest project. I tried some things in Dockerfile and docker-compose, but when I start the container and go to browser to localhost:3042 it says the page isn't working, but it should GET an object.
So right now, my Dockerfile looks like this:
FROM node:10
WORKDIR /microservices
COPY package*.json ./
COPY tsconfig.json tsconfig.json
COPY src src
RUN ["npm","install","global","#nestjs/cli"]
RUN ["npm", "install"]
EXPOSE 3042
ENTRYPOINT ["npm","run","start"]
And my docker-compose.yaml looks like this:
version: "3.2"
services:
server:
container_name: server
hostname: localhost
build: ./
ports:
- "3042:3042"
I run docker-compose up, go to browser and it doesn't work.
The output of the docker-compose up command is:
server | [Nest] 18 - 07/12/2019, 1:44 PM [NestFactory] Starting Nest application...
server | [Nest] 18 - 07/12/2019, 1:44 PM [InstanceLoader] AppModule dependencies initialized +26ms
server | [Nest] 18 - 07/12/2019, 1:44 PM [RoutesResolver] AppController {/}: +10ms
server | [Nest] 18 - 07/12/2019, 1:44 PM [RouterExplorer] Mapped {/, GET} route +7ms
server | [Nest] 18 - 07/12/2019, 1:44 PM [NestApplication] Nest application successfully started +5ms
So it seems like inside something is going on and the app starts successfully.
I looked on some examples, the one from their documentation where python is used and another example with Express.js, but didn't help me.
In my case, I was using FastifyAdapter, and it so happens that when being inside docker, you have to specify the host as "0.0.0.0" instead of localhost. The thing is, you have to add the host as a second parameter, instead of concatenate the strings:
WRONG
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());
await app.listen("0.0.0.0:3000");
CORRECT
const app = await NestFactory.create(AppModule);
await app.listen(3000, "0.0.0.0");
Nest is using the port 3000 by default, so I think that's the problem. You can try to change it in the main.ts:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3042);
}
or changing your docker configuration.
Dockerfile
EXPOSE 3000/tcp
docker-compose.yml
version: "3.2"
services:
server:
container_name: server
hostname: localhost
build: ./
ports:
- 3000:3000
If anyone is having the same issue, my problem was that I added a second argument in app.listen
change it from this:
await app.listen(this.port, this.host);
to this
await app.listen(this.port);
solved my issue

Setting Docker for laravel app I got errors in "compose/cli/main.py

In my Kubuntu 18.04 I try to run docker for my Laravel application
$ docker --version
Docker version 17.12.1-ce, build 7390fc6
I have 3 files:
.env:
# PATHS
DB_PATH_HOST=./databases
APP_PATH_HOST=./votes
APP_PTH_CONTAINER=/var/www/html/
docker-compose.yml:
version: '3'
services:
web:
build: ./web/Dockerfile.yml
environment:
- APACHE_RUN_USER=www-data
volumes:
- ${DB_PATH_HOST}:${APP_PTH_CONTAINER}
ports:
- 8080:80
working_dir: ${APP_PTH_CONTAINER}
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1
volumes:
- ${DB_PATH_HOST}:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
composer:
image: composer:1.6
volumes:
- ${DB_PATH_HOST}:${APP_PTH_CONTAINER}
working_dir: ${APP_PTH_CONTAINER}
command: composer install
/web/Dockerfile.yml:
FROM php:7.2-apache
RUN docker-php-ext-install \
pdo_mysql \
&& a2enmod \
rewrite
When I try to use docker-compose up --build, I get the following:
serge#serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker-compose up --build
Building web
Traceback (most recent call last):
File "bin/docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 1052, in up
File "compose/cli/main.py", line 1048, in up
File "compose/project.py", line 466, in up
File "compose/service.py", line 329, in ensure_image_exists
File "compose/service.py", line 1047, in build
File "site-packages/docker/api/build.py", line 142, in build
TypeError: You must specify a directory to build in path
[6769] Failed to execute script docker-compose
I know that *.py that is python language files, but I do not use python language or work with it, I work with PHP.
Why is an error and how to fix it?
MODIFIED:
$ docker-compose up --build
Building webapp
Step 1/2 : FROM php:7.2-apache
---> a7d68dad7584
Step 2/2 : RUN docker-php-ext-install pdo_mysql && a2enmod rewrite
---> Using cache
---> 519d1b33af81
Successfully built 519d1b33af81
Successfully tagged votes_docker_webapp:latest
Starting votes_docker_adminer_1 ...
Starting votes_docker_composer_1 ...
Starting votes_docker_adminer_1 ... error
votes_docker_db_1 is up-to-date
ERROR: for votes_docker_adminer_1 Cannot start service adminer: driver failed programming external connectivity on endpoint votes_docker_adminer_1 (6e94693ab8b1a990aaa83164df0952e8665f351618a72aStarting votes_docker_composer_1 ... done
ERROR: for adminer Cannot start service adminer: driver failed programming external connectivity on endpoint votes_docker_adminer_1 (6e94693ab8b1a990aaa83164df0952e8665f351618a72a5531f9c3ccc18a2e3d): Bind for 0.0.0.0:8080 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
I tried to check related ports and got:
# sudo netstat -ntpl | grep 8080:8080
# sudo netstat -ntpl | grep 0.0.0.0:8080
# sudo netstat -ntpl | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 7361/docker-proxy
MODIFIED #2:
serge#serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker-compose up --build
Creating network "votes_docker_default" with the default driver
Building webapp
Step 1/2 : FROM php:7.2-apache
---> a7d68dad7584
Step 2/2 : RUN docker-php-ext-install pdo_mysql && a2enmod rewrite
---> Using cache
---> 519d1b33af81
Successfully built 519d1b33af81
Successfully tagged votes_docker_webapp:latest
Creating votes_docker_adminer_1 ... done
Creating votes_docker_composer_1 ... done
Creating votes_docker_webapp_1 ... done
Creating votes_docker_db_1 ... done
Attaching to votes_docker_adminer_1, votes_docker_composer_1, votes_docker_webapp_1, votes_docker_db_1
adminer_1 | PHP 7.2.10 Development Server started at Mon Oct 15 10:14:02 2018
composer_1 | Composer could not find a composer.json file in /var/www/html
composer_1 | To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
votes_docker_composer_1 exited with code 1
webapp_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.4. Set the 'ServerName' directive globally to suppress this message
webapp_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.4. Set the 'ServerName' directive globally to suppress this message
webapp_1 | [Mon Oct 15 10:14:05.281793 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.10 configured -- resuming normal operations
webapp_1 | [Mon Oct 15 10:14:05.281843 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
db_1 | 2018-10-15T10:14:06.541323Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
db_1 | 2018-10-15T10:14:06.541484Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.11) starting as process 1
db_1 | mbind: Operation not permitted
db_1 | mbind: Operation not permitted
db_1 | mbind: Operation not permitted
db_1 | mbind: Operation not permitted
db_1 | 2018-10-15T10:14:07.062202Z 0 [Warning] [MY-011071] [Server] World-writable config file './auto.cnf' is ignored.
db_1 | 2018-10-15T10:14:07.062581Z 0 [Warning] [MY-010107] [Server] World-writable config file './auto.cnf' has been removed.
db_1 | 2018-10-15T10:14:07.063146Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0cd8212e-d063-11e8-8e69-0242ac140005.
db_1 | 2018-10-15T10:14:07.079020Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1 | 2018-10-15T10:14:07.091951Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2018-10-15T10:14:07.103829Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.103896Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.103925Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.103947Z 0 [Warning] [MY-010315] [Server] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.104006Z 0 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.104034Z 0 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.104070Z 0 [Warning] [MY-010311] [Server] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.112700Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.112738Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-10-15T10:14:07.117764Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.11' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
Is it mysql misconfigure?
I run it not as root.
Also as I use LAMP do I need to stop apache and mysql before running docker-compose command?
MODIFIED #3:
After some searching I added mysql version in my config file and added command option:
image: mysql:5.7.23
command: --default-authentication-plugin=mysql_native_password --disable-partition-engine-check
and the above error was fixed.
So:
1. In other console under root I run commands (but I'm still not sure if I need it?)
sudo service apache2 stop
sudo service mysql stop
2. Under nonroot console I run with key to run in background:
docker-compose up -d
serge#serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker-compose down
Stopping votes_docker_db_1 ... done
Stopping votes_docker_webapp_1 ... done
Stopping votes_docker_adminer_1 ... done
Removing votes_docker_db_1 ... done
Removing votes_docker_webapp_1 ... done
Removing votes_docker_composer_1 ... done
Removing votes_docker_adminer_1 ... done
Removing network votes_docker_default
docker-compose up -d
Creating network "votes_docker_default" with the default driver
Creating votes_docker_webapp_1 ... done
Creating votes_docker_adminer_1 ... done
Creating votes_docker_db_1 ... done
Creating votes_docker_composer_1 ... done
I have no errors in output, but I expected as a result to have vendor directory in my project, as I have in web/Dockerfile.yml:
FROM php:7.2-apache
RUN docker-php-ext-install \
pdo_mysql \
&& a2enmod \
rewrite
But I do not see this directory...
Was the installation successful or not?
I'm not sure where to move next?
serge#serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker info
Containers: 33
Running: 2
Paused: 0
Stopped: 31
Images: 19
Server Version: 17.12.1-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9b55aab90508bd389d7654c4baf173a981477d55
runc version: 9f9c96235cc97674e935002fc3d78361b696a69e
init version: v0.13.0 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.15.0-36-generic
Operating System: Ubuntu 18.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.711GiB
Name: serge
ID: BDNU:HFWX:N6YV:IWYW:HJSU:SZ23:URPB:3FR2:7I3E:IFGK:AOLH:YRE5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
serge#serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
votes_docker_webapp latest 519d1b33af81 27 hours ago 378MB
adminer latest 0038b45402de 4 weeks ago 81.7MB
composer 1.6 e28b5b53ab28 4 weeks ago 154MB
php 7.2-apache a7d68dad7584 4 weeks ago 378MB
mysql 5.7.23 563a026a1511 5 weeks ago 372MB
mysql 5.7.22 6bb891430fb6 2 months ago 372MB
test2_php latest 05534d47f926 3 months ago 84.7MB
test1_php latest 05534d47f926 3 months ago 84.7MB
<none> <none> 6060fcf4d103 3 months ago 81MB
php fpm-alpine 601d5b3a95d4 3 months ago 80.6MB
php apache d9faf33e6e40 3 months ago 377MB
mysql latest 8d99edb9fd40 3 months ago 445MB
php 7-fpm 854ffd8dc9d8 3 months ago 367MB
php 7.2 e86d9bb526ef 3 months ago 367MB
ukfx/php apache-stretch 5958cb7c2316 4 months ago 648MB
nginx alpine bc7fdec94612 4 months ago 18MB
hello-world latest e38bc07ac18e 6 months ago 1.85kB
composer/composer latest 5afb0951f2a4 2 years ago 636MB
serge#serge:/mnt/_work_sdb8/wwwroot/lar/DockerApps/votes_docker$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f8beea5dceca mysql:5.7.23 "docker-entrypoint.s…" 6 minutes ago Restarting (2) 6 seconds ago votes_docker_db_1
8309b5456dcf adminer "entrypoint.sh docke…" 6 minutes ago Up 6 minutes 0.0.0.0:8081->8080/tcp votes_docker_adminer_1
cc644206931b votes_docker_webapp "docker-php-entrypoi…" 6 minutes ago Up 6 minutes 0.0.0.0:8080->80/tcp votes_docker_webapp_1
How to fix it?
Thanks!
According to docker-compose documentation, build can be specified as a string containing a path to the build context if you have Dockerfile inside it.
You are using Dockerfile.yml file, which is not a default one (Dockerfile), so in this case context and dockerfile should be specified as well:
web:
build:
context: ./web
dockerfile: Dockerfile.yml
The final docker-compose.yaml is:
version: '3'
services:
web:
build:
context: ./web
dockerfile: Dockerfile.yml
environment:
- APACHE_RUN_USER=www-data
volumes:
- ${DB_PATH_HOST}:${APP_PTH_CONTAINER}
ports:
- 8080:80
working_dir: ${APP_PTH_CONTAINER}
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1
volumes:
- ${DB_PATH_HOST}:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
composer:
image: composer:1.6
volumes:
- ${DB_PATH_HOST}:${APP_PTH_CONTAINER}
working_dir: ${APP_PTH_CONTAINER}
command: composer install
Addition to MODIFIED part:
Both web and adminer are configured to be allocated on port 8080 on a host system. That's why you have a conflict here. To resolve above issue you need to bind adminer to another port 8081 for example.
The final docker-compose.yaml is:
version: '3'
services:
web:
build:
context: ./web
dockerfile: Dockerfile.yml
environment:
- APACHE_RUN_USER=www-data
volumes:
- ${DB_PATH_HOST}:${APP_PTH_CONTAINER}
ports:
- 8080:80
working_dir: ${APP_PTH_CONTAINER}
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1
volumes:
- ${DB_PATH_HOST}:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8081:8080
composer:
image: composer:1.6
volumes:
- ${DB_PATH_HOST}:${APP_PTH_CONTAINER}
working_dir: ${APP_PTH_CONTAINER}
command: composer install
Addition to MODIFIED3 part:
I see the following error with your composer docker container:
composer_1 | Composer could not find a composer.json file in /var/www/html
composer_1 | To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Is it because you accidentally put ${DB_PATH_HOST} instead of ${APP_PATH_HOST} in the composer config?
composer:
image: composer:1.6
volumes:
- ${DB_PATH_HOST}:${APP_PTH_CONTAINER}
working_dir: ${APP_PTH_CONTAINER}
command: composer install

Docker: Permission denied when PHP upload file to mounted data volume

I'm using docker quickstart terminal on Win10.
Client:
Version: 17.06.0-ce,
API version: 1.30
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:30:30 2017
OS/Arch: windows/amd64
I have a simple document upload php script that saves an uploaded document to a file location called '/uploads'.
I want to make the '/uploads' folder a volume attached to the php:apache container, so i can easily share the contents with the python back-end.
I'm using the following docker-compose.yml file to build a web service with a python back-end.
Note: The php works on the php:apache environment without the volume.
$ docker volume create fileul --opt o=uid=197609,gid=0
version: '3.2'
services:
Python_app:
build: ./product
volumes:
- ./product:/usr/src/app
ports:
- 5001:80
website:
image: php:apache
volumes:
- ./website:/var/www/html
- type: volume
source: fileuld
target: /var/www/html/uploads
read_only: false
ports:
- 5000:80
depends_on:
- Python_app
volumes:
fileuld:
I get a permission error on the web service when I try to upload a document to the attached volume fileuld. failed to open stream: Permission denied in /var/www/html/upload.php
I have read some other stackoverflow posts on this and they talk about uid and gid and i have tried using :
$ls -ls
Which gives the following:
4 -rw-r--r-- 1 ASUSNJHOME 197609 343 Sep 23 14:49 docker-compose.yml
32 drwxr-xr-x 1 ASUSNJHOME 197609 0 Sep 22 07:10 product/
0 drwxr-xr-x 1 ASUSNJHOME 197609 0 Sep 23 15:38 volume-example/
0 drwxr-xr-x 1 ASUSNJHOME 197609 0 Sep 22 21:32 website/
But i can't work out how to have the volume able to accept a document getting written into or how to change the permissions of it when it is being created from the docker-compose file.
Can anyone point me in the right direction?
Thanks
Michael

Resources