Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

issue with the docker compose file

I was trying the example provided in the link below for wordpress linking with mysql.

https://www.sitepoint.com/how-to-use-the-official-docker-wordpress-image/

I tried working without the volumes and its working fine. However, when I added volumes in the docker-compose.yml file, it started to give me the following error

ERROR: yaml.scanner.ScannerError: mapping values are not allowed here
  in "./docker-compose.yml", line 16, column 12

docker-compose.yml file

web:
image: wordpress
links:
 - mysql
environment:
 - WORDPRESS_DB_PASSWORD=password
ports:
 - "127.0.0.3:8080:80"
mysql:
image: mysql:5.7
environment:
 - MYSQL_ROOT_PASSWORD=password
 - MYSQL_DATABASE=wordpress

working_dir: /var/www/html
volumes:
 - wordpress/wp-content/: /home/tgandhi

Thanks for helping.

like image 913
Tushar Gandhi Avatar asked Feb 06 '17 03:02

Tushar Gandhi


People also ask

Where is my Docker compose file?

The default path for a Compose file is ./docker-compose.yml .

What can I do with Docker compose file?

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services. Then, with a single command, you create and start all the services from your configuration.

Is Docker compose the same as Docker compose?

The key difference between docker run versus docker-compose is that docker run is entirely command line based, while docker-compose reads configuration data from a YAML file. The second major difference is that docker run can only start one container at a time, while docker-compose will configure and run multiple.


1 Answers

First of all, working_dir and volumes need to go into the web section of your compose file, not in the mysql section.

Secondly, the volume mapping is <host path>:<container path>.

As you specified /var/www/html as your working dir, the wordpress image uses /var/www/html/wp-content as the base directory. So you need to mount the directory on your host with static files into /var/www/html/wp-content. I assuming this to be ~/wordpress.

web:
  image: wordpress
  links:
    - mysql
  environment:
    - WORDPRESS_DB_PASSWORD=password
  ports:
    - "127.0.0.3:8080:80"
  working_dir: /var/www/html
  volumes:
    - /home/tgandhi/wordpress:/var/www/html/wp-content

mysql:
  image: mysql:5.7
  environment:
    - MYSQL_ROOT_PASSWORD=password
    - MYSQL_DATABASE=wordpress
like image 159
Martin Avatar answered Oct 30 '22 07:10

Martin