can't start docker-compose services - docker

when I run this docker compose file I have a strange error. that you can see under the text. I'm new with dock so can anyone help me with this.
The error:
ERROR: The compose file './docker-compose.yaml is invalid because:
services.wordpress.build contains an invalid type, it should be a string, or an object
My docker-compose file:
version: "3.7"
services:
db:
build: ./db
container_name: db
ports:
- "3306:3306"
volumes:
- db_data:/var/lib.mysql
environment:
MYSQL_ROOT_PASSWORD: Test123
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: Test123
networks:
website_network:
aliases:
- wordpress
wordpress:
build:
container_name: wordpress_new
ports:
- "80:80"
networks:
website_network:
aliases:
- wordpress
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: Test123
WORDPRESS_DB_NAME: wordpress
networks:
website_networks:
name: website_network
volumes:
db_data:
driver: local
name: db_data

Your services.wordpress.build config option needs a value after it like you did in services.db.build: ./db. This value represents where to find your Dockerfile and the context where Docker will try to build your image.
Check the docs on how you can specify the build option.
This is what your file should look like in the wordpress section:
wordpress:
build: BUILD_PATH_HERE # you need a value here if you're building a new docker image
Per the docs, note that if your Dockerfile has an alternate name or you need a special build context, you'll need to specify those values as well as an object. For example:
wordpress:
build:
context: ./some/context/path # can be a relative or absolute path
dockerfile: Dockerfile-alternate-name
Alternatively, if you're using a prebuilt image, you can specify:
wordpress:
image: IMAGE_NAME

You are missing the build property value.
wordpress:
build: SOMETHING NEEDS TO BE HERE
container_name: wordpress_new
A path to where the build runs or a more complex object. Probably just the name of the folder where the container sources are.
This is how it can look like: object if it is an object. And this is how it can look like if it is just a path: path
More info: https://docs.docker.com/compose/compose-file/compose-file-v3/#build

Related

Volume defined in docker-compose.yml shows up empty

I have the following in my docker-compose.yml file:
version: '3.9'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
- db_import:/import
restart: always
ports:
- "3338:3306"
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
volumes:
db_data: {}
db_import: {}
dist: {}
The problem is that even though I have a dump.sql file in my db_import folder (inside the same folder where docker-compose.yml resides), I find that docker-compose exec db ls -al /import shows an empty directory. I've tried restarting all docker containers without any improvement.
Why is this directory not passing my content through?
By writing:
volumes:
- db_data:/var/lib/mysql
- db_import:/import
(...)
volumes:
db_data: {}
db_import: {}
dist: {}
You created so called Named Volumes with names db_data, db_import and dist. Docker doesn't tell us where those volumes are stored (and we shouldn't care about that). That kind of volumes is used to share data between containers and they do not have access to anything from your host machine.
If you want to share files beetween your host and container you must use Mount Binds instead - syntax is almost identical, you just need to replace db_data and db_import with absolute paths to that directories:
version: '3.9'
services:
db:
image: mysql:5.7
volumes:
- /PATH/TO/db_data:/var/lib/mysql
- /PATH/TO/db_import:/import
restart: always
ports:
- "3338:3306"
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
#volumes: That part isn't needed unless you use "dist" volume somewhere
# db_data: {}
# db_import: {}
# dist: {}

Volume edited by systemd-coredump docker

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.

yml docker-compose error mapping values are not allowed here

I try to learn about container, but i have a problem with my docker-compose.yml file, after i run the docker compose up, i always get the same error:
"ERROR: yaml.scanner.ScannerError: mapping values are not allowed
here"
even if i changed the mount path to docker volume, i got the same error, this is my yml file
version: "3"
services:
database:
image: mariadb
ports:
- "3260:3260"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/mariadb:var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
wordpress:
image: wordpress
ports:
- "2000:80"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/wordpress:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- database
links:
- database
It appears that your yaml is invalid. When I face these types of issues, what I will do is use a site called http://www.yamllint.com/ which will validate the syntax for you.
This yaml based on your example is valid:
Note: You can use 4 spaces (or 2 which I prefer), but never use tabs.
version: "3"
services:
database:
environment:
MYSQL_ROOT_PASSWORD: root
image: mariadb
ports:
- "3260:3260"
volumes:
- "/home/randy/Desktop/Latihan/wordpress-mariadb/mariadb:var/lib/mysql"
wordpress:
image: wordpress
ports:
- "2000:80"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/wordpress:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- database
links:
- database

Can't figure out how i misconfigurated my docker-compose file

I followed multiple guides and tutorials.
This is my docker-compose file.
It gives the following error,
services.mysql.environment.volumes contains ["mysql_data:/var/lib/mysql"], which is an invalid type, it should be a string, number, or a null
And it creates a volume with the name _volumename?
I just don't seem to get the mistake i made.
version : '3'
services:
mysql:
container_name: auth_db
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: name
MYSQL_USER: user
MYSQL_PASS: supersecret2
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
auth-service:
build: ./authservice
volumes:
- ./authservice:/usr/src/app
ports:
- 5000:5000
volumes:
mysql_data:
Some more information.
If i change the volume line to
volumes: "- mysql_data:/var/lib/mysql"
The docker-compose file will compile but
docker volume ls gives this output
local 4fa81a11596c2b67c2bb799d54afc6009ebcd82fcd10acae53a5aeefd005fd36
local 8636df909155569e8ebf0649f4c192616d0b6778d5eb7932b1f9542db55a07d8
local 832739c89f3b33ad0a1974ad7dc2ee9342373f904af3b2be5934331bae50b5e6
local e5bb4a869f54ce3200d5a1fe129bc1f8ee46515cf03d9dd2ff327430d792117b
local e35a38127fcb07702a58133883a021aa56c4aad6c439d254f32a119ad380d808
local hell_mysql_data
My current dir where the docker-compose file is located is HELL that why i think it got the prefix from
Your issue is regarding indentation, volumes and ports must be top level first inside your service definition, as follows:
version : '3'
services:
mysql:
container_name: auth_db
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: name
MYSQL_USER: user
MYSQL_PASS: supersecret2
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
auth-service:
build: ./authservice
volumes:
- ./authservice:/usr/src/app
ports:
- 5000:5000
volumes:
mysql_data:

Docker-Compose persistent data MySQL

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

Resources