i have the following docker-compose.yml
The restart of the mediawiki_db container is working.
The problem is, that the mediawiki container will not restart after reboot besides the fact that it also has the restart: always policy.
# MediaWiki with MariaDB
#
# Access via "http://localhost:8080"
# (or "http://$(docker-machine ip):8080" if using docker-machine)
version: '2'
services:
mediawiki_db:
image: mariadb
restart: always
container_name: mediawiki_db
volumes:
- ~/wiki/mysql:/var/lib/mysql
environment:
# #see https://phabricator.wikimedia.org/source/mediawiki/browse/master/includes/DefaultSettings.php
MYSQL_DATABASE: 'my_wiki'
MYSQL_USER: 'wikiuser'
MYSQL_PASSWORD: 'pw'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
mediawiki:
image: mediawiki
restart: always
container_name: mediawiki
ports:
- 8080:80
volumes:
- ~/wiki/var/www/html/images:/var/www/html/images
# After initial setup, download LocalSettings.php to the same directory as
# this yaml and uncomment the following line and use compose to restart
# the mediawiki service
- ./LocalSettings.php:/var/www/html/LocalSettings.php
depends_on:
- mediawiki_db
What is it i am doing wrong?
As far as I can tell from the MediaWiki DockerFile, there is no CMD being run when you start up the container.
Someone correct me if I'm wrong, but I think the restart: always can only work if there is a command that docker-compose is monitoring. And therefore restart the container with.
Related
I am trying to build a Prestashop image using Docker Compose, I use this docker-compose.yml file
version: "3.7"
services:
app:
build: .
image: prestashop/prestashop:1.7
ports:
- 8080:80
working_dir: /var/www/html
volumes:
- ./:/var/www/html
environment:
PS_DOMAIN: localhost
DB_SERVER: mysql
MYSQL_USER: root
MYSQL_PASSWORD: mypass123
MYSQL_DB: prestashop
dns: 8.8.8.8
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mypass123
MYSQL_DATABASE: prestashop
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8081:80
environment:
MYSQL_ROOT_PASSWORD: mypass123
MYSQL_DATABASE: prestashop
PMA_HOST: mysql
But every time I start it, the server does not respond for several minutes (Firefox says "connection was reset"). And once I can eventually access to the webpage, it is very slow.
Is it something that I can solve by changing my docker-compose file ?
Thanks a lot !
You may use .dockerignore in your build.
This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon .
https://docs.docker.com/engine/reference/builder/#dockerignore-file
also check this out for best practices https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
I try to deploy mysql server on docker and when I try to change enviroment variables in my docker-compose.yml file they just don't change when I do docker-compose up.
I have noticed, that when I will remove container using docker container remove <process ID> and again try to docker-compose up it will works. If I will change name of the service in docker-compose.yml it will work too. Do I have always to remove stopped containers to restart enviroments variables or am I doing something wrong?
My docker-compose.yml file:
version: '3.3'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: 'db'
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password1'
MYSQL_ROOT_PASSWORD: 'password1'
ports:
- '3306:3306'
expose:
- '3306'
I'm trying to make a Symfony project running in docker container.
So, there is my docker-compose.yml :
version: '3.7'
services:
mariadb:
image: ${MARIADB_VERSION}
restart: on-failure
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- ${PORTS_MARIADB}
volumes:
- './db/:/var/lib/mysql'
php:
build:
context: .
dockerfile: docker/php/Dockerfile
volumes:
- './app/:/usr/src/app'
restart: on-failure
user: 1000:1000
nginx:
image: ${NGINX_VERSION}
restart: on-failure
volumes:
- './app/public/:/usr/src/app'
- './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro'
ports:
- ${PORTS_NGINX}
depends_on:
- php
I start my container like this (with non-root user):
docker-compose build
docker-compose up -d
So, at this point, all is ok but, If I want to re-build my docker container:
docker-compose down
docker-compose build
The volume ./db (of mariadb) have his permissions set to systemd-coredump:findl users (findl is mine)
So, I have this error when I try to build the container:
Why the permissions to the volume /db are set to another user... ?
Regards
As a result of this Github issue reply, I was able to fix my issues and move on. Basically, take the temporary portion of your volume and add it to .dockerignore. The commenter does a much better explanation of why it works than I would ever be able to muster here, but if this gets you (or anyone else who runs into this issue) farther along, then so be it.
I have write a docker compose file, I want to start compose use
docker-compose up -d
But I want to pass args to my images
It look like
docker run --security-opt=seccomp:unconfined mysql:8.0
But I find compose file only have basic config such as network, volume, environment
My compose file
db:
image: mysql:8.0
container_name: onlinecodedb
volumes:
- onlinecode-database:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: mysqlrootpassword
MYSQL_PASSWORD: mysqlpassword
MYSQL_USER: mysql
MYSQL_DATABASE: onlinecode
ports:
- "3300:3306"
networks:
- onlinecode-net
How I solve this problem?
Most of the docker run options have matching Docker Compose options. In particular, docker run --security-opt maps to a security_opt: field.
db:
image: 'mysql:8.0'
security_opt:
- 'seccomp:unconfined'
et: cetera
I can't seem to get MySQL data to persist if I run $ docker-compose down with the following .yml
version: '2'
services:
# other services
data:
container_name: flask_data
image: mysql:latest
volumes:
- /var/lib/mysql
command: "true"
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes_from:
- data
ports:
- "3306:3306"
My understanding is that in my data container using volumes: - /var/lib/mysql maps it to my local machines directory where mysql stores data to the container and because of this mapping the data should persist even if the containers are destroyed. And the mysql container is just a client interface into the db and can see the local directory because of volumes_from: - data
Attempted this answer and it did not work. Docker-Compose Persistent Data Trouble
EDIT
Changed my .yml as shown below and created a the dir ./data but now when I run docker-compose up --build the mysql container wont start throws error saying
data:
container_name: flask_data
image: mysql:latest
volumes:
- ./data:/var/lib/mysql
command: "true"
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes_from:
- data
ports:
- "3306:3306"
flask_mysql | mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)
flask_mysql | 2016-08-26T22:29:21.182144Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
flask_mysql | 2016-08-26T22:29:21.185392Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
The data container is a superfluous workaround. Data-volumes would do the trick for you. Alter your docker-compose.yml to:
version: '2'
services:
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes:
- my-datavolume:/var/lib/mysql
volumes:
my-datavolume:
Docker will create the volume for you in the /var/lib/docker/volumes folder. This volume persist as long as you are not typing docker-compose down -v
There are 3 ways:
First way
You need specify the directory to store mysql data on your host machine. You can then remove the data container. Your mysql data will be saved on you local filesystem.
Mysql container definition must look like this:
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes:
- /opt/mysql_data:/var/lib/mysql
ports:
- "3306:3306"
Second way
Would be to commit the data container before typing docker-compose down:
docker commit my_data_container
docker-compose down
Third way
Also you can use docker-compose stop instead of docker-compose down (then you don't need to commit the container)
first, you need to delete all old mysql data using
docker-compose down -v
after that add two lines in your docker-compose.yml
volumes:
- mysql-data:/var/lib/mysql
and
volumes:
mysql-data:
your final docker-compose.yml will looks like
version: '3.1'
services:
php:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- ./src:/var/www/html/
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- mysql-data:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
volumes:
mysql-data:
after that use this command
docker-compose up -d
now your data will persistent and will not be deleted even after using this command
docker-compose down
extra:- but if you want to delete all data then you will use
docker-compose down -v
You have to create a separate volume for mysql data.
So it will look like this:
volumes_from:
- data
volumes:
- ./mysql-data:/var/lib/mysql
And no, /var/lib/mysql is a path inside your mysql container and has nothing to do with a path on your host machine. Your host machine may even have no mysql at all. So the goal is to persist an internal folder from a mysql container.
Adding on to the answer from #Ohmen, you could also add an external flag to create the data volume outside of docker compose. This way docker compose would not attempt to create it. Also you wouldn't have to worry about losing the data inside the data-volume in the event of $ docker-compose down -v.
The below example is from the official page.
version: "3.8"
services:
db:
image: postgres
volumes:
- data:/var/lib/postgresql/data
volumes:
data:
external: true
Actually this is the path and you should mention a valid path for this to work. If your data directory is in current directory then instead of my-data you should mention ./my-data, otherwise it will give you that error in mysql and mariadb also.
volumes:
./my-data:/var/lib/mysql
Feasible bind mount solution:
mariadb:
image: mariadb:latest
restart: unless-stopped
environment:
- MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
volumes:
- type: bind
source: /host/dir
target: /var/lib/mysql