Docker: Cannot locate specified Dockerfile error - nginx

I want to make a platform for web development on my PC (MacOS) by using docker. After installing nginx in docker container, I wanted to build nginx. I got this error.
Cannot locate specified Dockerfile:nginx.docker
I searched on the Internet, but I cannot solve my problem.
Container information (docker ps -a):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2f268b825ba3 nginx:latest "nginx -g 'daemon off" 39 minutes ago Up 39 minutes 443/tcp, 0.0.0.0:8081->80/tcp dockertutorial_nginx_1
This is my docker-compose.yml file:
nginx:
container_name: dockertutorial_nginx_1
build: .
dockerfile: nginx.docker
ports:
- 80:8081
links:
- php
volumes:
- .:/Users/user/docker-tutorial
php:
image: php:7.0-fpm
expose:
- 9000
volumes:
- .:/Users/user/docker-tutorial
How can I solve this problem?

I solved it with the location of Dockerfile. The docker cannot find dockerfile. That's why, I got this error. Btw, thanks to #harald Nordgren.

Related

Docker container taking 27GB on disk while docker container ls --size only report 500MB

I'm on a Debian VPS on OVH cloud provider, running Docker.
Trying to make an apt update on the instance, I noticed that the disk of 40GB was full. What is quite surprising for an instance hosting 2 Wordpress blogs.
I tried to run:
sudo du -h /var/lib/docker/containers
One of the containers weight 27GB !
27G /var/lib/docker/containers/1618df0(...)d6cc61e
However when I run:
docker container ls --size
The same container only weight 500MB
1618df0(...) 782c(...) "docker-entrypoint.s…" 10 months ago Up 10 months 80/tcp blog_wordpress_1 2B (virtual 545MB)
The Docker Compose is pretty simple:
wordpress:
build:
# call the Dockerfile in ./wordpress
context: ./wordpress
restart: always
environment:
# Connect WordPress to the database
WORDPRESS_DB_HOST: db:xxxx
WORDPRESS_DB_USER: xxxx
WORDPRESS_DB_PASSWORD: xxxx
WORDPRESS_DB_NAME: xxxx
volumes:
# save the content of WordPress an enable local modifications
- ./wordpress/data:/var/www/html
networks:
- traefik
- backend
depends_on:
- db
- redis
The Dockerfile:
FROM wordpress
# printf statement mocks answering the prompts from the pecl install
RUN printf "\n \n" | pecl install redis && docker-php-ext-enable redis
RUN /etc/init.d/apache2 restart
Do you know what to investigate to understand this problem ?
Thanks
Ok, this was actually the logs... The logs are not counted by:
docker container ls --size
So I just truncated the logs, brutally:
sudo sh -c "truncate -s 0 /var/lib/docker/containers/*/*-json.log"
This solve the problem for a while.
For the long term, I added these lines to the Wordpress container's Docker Compose, then deleted and recreated the containers:
logging:
options:
max-size: "10m"
max-file: "3"

nginxproxy/nginx-proxy not resolving VIRTUAL_HOST as expected

I would like to use a reverse proxy with this docker-compose.yml
services:
nginx-proxy:
image: nginxproxy/nginx-proxy
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
depends_on:
- hello-world
hello-world:
image: nginx
ports:
- 9001:80
environment:
VIRTUAL_HOST: hello.world
volumes:
- ./web:/usr/share/nginx/html
What I expect to happen is that curl -H "Host: hello.world" localhost:80 would return the index.html in the folder web. But actually it is return the "Welcome to nginx!" page so it seems it does not resolve the VIRTUAL_HOST at all.
What actually works as expected is the following call: curl -H "Host: hello.world" localhost:9001 which return the index.html as expected. But why cannot it resolve the hostname?. Eventually this is a very minimal example of my setup.
It is running on an arm64 machine with docker version: Docker version 20.10.6, build 370c28948e.
What fundamental mistake am I doing here? I tried to implement it as described on README of the nginx-proxy project.
EDIT:
When I start with docker-compose up -d and then run docker-compose ps I get:
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------
minimal-proxy-example_hello-world_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:9001->80/tcp,:::9001->80/tcp
minimal-proxy-example_nginx-proxy_1 /app/docker-entrypoint.sh ... Up 0.0.0.0:80->80/tcp,:::80->80/tcp
I am running docker on Arch Linux on a Raspberry Pi 4 using a AArch64 kernel. I tried the same on a normal Amd64 PC with the same result. However I tried also the very same with docker-desktop on Windows 10. I used a git-bash to be able to use curl. And there it all worked as expected! Why does this work on docker-desktop on Windows 10 but not on Arch Linux? As consequence I also posted this question in the Arch Linux forum.
Update
I think the problem relates to this bug: https://github.com/nginx-proxy/nginx-proxy/issues/1548

Docker permissions with Symfony 3

There is problem with symfony cache and logs in docker containers.
Web server executes from www-data user and group and when I do symfony cache clear from docker container using php that is installed on docker, it executes from root.
So if I remove var/logs/dev.log for example and open url in browser, new log.dev gets created with user and group: www-data:www-data, but after i do cache clear, it gets permissions root:root and url in browser gives error dev.log permission denied.
I am not sure whats the problem, but I guess somehow nginx operates under www-data and when I execute console commands they operate from root user.
I have 4 containers: nginx, php-fpm, mysql, rabbit.
I also use version 3 of docker compose, I thought of solution with group_add but its no longer available in version 3
How do I configure this?
=================
docker-compose is similar to this:
version: "3"
services:
nginx:
image: nginx:1.11
depends_on:
- php-fpm
links:
- php-fpm
environment:
- NGINX_PORT=80
- FASTCGI_HOST=php
- FASTCGI_PORT=9000
- DOCUMENT_ROOT=/usr/local/src/test-project/public
ports:
- 8095:80
volumes:
- .:/usr/local/src/test-project
- ./docker/nginx/templates/default.conf.template:/etc/nginx/conf.d/default.conf.template
- ./docker/nginx/entrypoint.sh:/entrypoint.sh
command: "/bin/bash /entrypoint.sh"
php-fpm:
build: docker/php
depends_on:
- db
extra_hosts:
- "test-project:127.0.0.1"
environment:
DATABASE_URL: pgsql://test-project_users:test-project_users#db:5432/test-project_users
APP_URL: 172.19.0.1:8095/
working_dir: /usr/local/src/test-project
volumes:
- .:/usr/local/src/test-project
db:
image: postgres
restart: always
ports:
- '5599:5432'
environment:
POSTGRES_DB: test-project_users
POSTGRES_USER: test-project_users
POSTGRES_PASSWORD: test-project_users
volumes:
- data:/var/lib/db
The problem is, that you are clearing the cache as root user via command-line. you should run the clear statement with su www-data.

docker-compose wordpress mysql connection refused

I've created a small docker-compose.yml which used to work like a charm to deploy small WordPress instances. It looks like this:
wordpress:
image: wordpress:latest
links:
- mysql
ports:
- "1234:80"
environment:
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_PASSWORD: "password"
WORDPRESS_DB_HOST: mariadb
MYSQL_PORT_3306_TCP: 3306
volumes:
- /srv/wordpress/:/var/www/html/
mysql:
image: mariadb:latest
mem_limit: 256m
container_name: mariadb
environment:
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: "password"
volumes:
- /srv/mariadb:/var/lib/mysql
But when I start it now (maybe since docker update to Docker version 1.9.1, build a34a1d5), it fails
wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) Connection refused
When I cat /etc/hosts of the wordpress_1 there are entries for MySQL:
172.17.0.10 mysql 12a564fdbc56 mariadb
and I am able to ping the MariaDB server.
When I docker-compose up, WordPress gets installed and after several restarts the MariaDB container prints:
Version: '10.0.22-MariaDB-1~jessie' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
Which schould indicate it to be running, isn't it?
How do I get the WordPress to be able to connect to the MariaDB container?
To fix this issue the first thing to do is:
Add the following code to wordpress & database containers (in the docker-compose file):
restart: unless-stopped
This will make sure you Database is started and intialized before wordpress container trying to connect to it. Then restart docker engine
sudo restart docker
or (for ubuntu 15+)
sudo service docker restart
Here the full configuration that worked for me, to setup wordpress with MariaDB:
version: '2'
services:
wordpress:
image: wordpress:latest
links:
- database:mariadb
environment:
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_NAME=mydbname
- WORDPRESS_TABLE_PREFIX=ab_
- WORDPRESS_DB_PASSWORD=password
- WORDPRESS_DB_HOST=mariadb
- MYSQL_PORT_3306_TCP=3306
restart: unless-stopped
ports:
- "test.dev:80:80"
working_dir: /var/www/html
volumes:
- ./wordpress/:/var/www/html/
database:
image: mariadb:latest
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=mydbname
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=password
restart: unless-stopped
ports:
- "3306:3306"
The reason for this behaviour probably was related to a recent kernel and docker update. I recognized several other connection issues in other docker-compose setups. Therefore I restarted the server (not just the docker service) and didn't have had any issues like this ever since.
I had almost same problem, but just restarting the Wordpress container saved me:
$ docker restart wordpress
I hope this help many people.
I too had troubles here. I was using docker-compose to set up multiple wordpress websites on a single (micro) Virtual Private Server, including phpmyadmin and jwilder/nginx-proxy as a controller.
$ docker logs XXXX will help indicate areas of concern. In my case, the MariaDB databases would keep restarting all the time.
It turns out that all that stuff just wouldn't fit on a micro 512M Single CPU service. I never received error messages that told me directly that size was an issue, but after adding things up, I realized that when all the databases were starting up, I was running out of memory. An upgrade to 1Gb, 1 CPU service worked just fine.
I was using your docker-compose.yml, had the same problem. Just restarting didn't fix. After nearly an hour of researching the logs, I found the problem was: wordpress service started connecting mysql service before it had fully started. Simply adding depends_on won't help.Docker Compose wait for container X before starting Y
the work around could be start the db server before Up. When it has fully started, run docker-compose up. Or just use external service.
This simply means you are trying to connect to the wrong host. In order to use this in localhost just use the name of your service as the database host example in your case, it would be mysql you can fix this by specifying the name of the localhost with a default variable like this MYSQL_ROOT_HOST: localhost
In my case, I'm using Mysql (not MariaDb) but I had the same problem.
After upgrading the MySQL version, it's works fine.
You can see my open source docker-compose configuration: https://github.com/rimiti/wordpress-dockerized-environment

Docker - wordpress deployed on Digital Ocean Droplet - where is the wp-content?

Testing the Docker eco-system, I deployed my containers with docker-compose on a Digital Ocean droplet (created with docker-machine..) it's running fine
the docker-compose.yml file is quite simple, using standard images
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=password
ports:
- "80:80"
working_dir: /var/www/html
volumes:
- wp-content/:/var/www/html/wp-content
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=wordpress
I can easily query the droplet url in my browser.
When I ssh into the droplet, I am searching for the wp-content folder in the droplet host, which is mounted as /usr/www/html/wp-content but I cannot find it... also the /var/www/html directory is empty... but the wordpress container is running
Where am I wrong ?
wrong path for volumes wp-content and wrong search in remote host ..
need to run :
docker exec -it bash to lsit files in container ....

Resources