Issue with docker compose: container command not found - php

I'm having an issue when trying to start multiple containers with docker-compose:
Dockerfile:
FROM nginx:1.9
ADD ./nginx-sites/default /etc/nginx/sites-available/default
docker-compose.yml:
version: "2"
services:
web:
build: .
ports:
- "80:80"
volumes:
- ./src:/var/www
links:
- fpm
fpm:
image: php:7-fpm
volumes:
- ./src:/var/www
When I use docker-compose up to start the application, I get the following error:
ERROR: Container command not found or does not exist.
Would love some help with this issue.

Like mentioned in the comments to the original question the php:fpm image requires for it's volume to be set to /var/www/html.
If you want to use a different dir you can work around that by using your own Dockerfile (based on php:fpm). That Dockerfile would like this:
FROM php:fpm
WORKDIR /var/www
It seems like setting the workdir to the desired dir does the trick.
Then in your docker-compose.yml you would build with that Dockerfile instead of using the php:fpm image directly.
version: "2"
services:
# ...
fpm:
build: ./path/to/dockerfile
volumes:
- ./src:/var/www

Related

COPY doesn't copy symfony project into php container

I try to dockerize a symfony project.
Docker compose at the root of the project:
version: "3"
services:
php:
build:
context: ./docker/php
nginx:
build:
context: ./docker/nginx
ports:
- 80:80
At the end of /docker/php/Dockerfile:
WORKDIR /var/www/symfony
COPY . /var/www/symfony
I expect whole project to be copied into /var/www/symfony
But when I:
docker exec -it my-container /bin/bash
What I see is an empty folder.
Why can't docker copy all directory structure into symfony folder?
I will assume that Symfony is installed at the root of your project's directory. If that is the case, then your build context is wrong.
Docker will only make the files inside your build context available during the build, you can see it as the root directory of the build.
If your context: ./docker/php is there in order to use a different Dockerfile, then you should specify the Dockerfile's path and keep . as your build context.
version: "3"
services:
php:
build:
context: .
dockerfile: ./docker/php/Dockerfile
nginx:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
ports:
- "80:80"
Let me know if that works

Difference between running docker and docker compose

I am working with an docker image nanoninja/php-fpm:8.1.
When I run the image manually, the PHP works.
docker container run --rm --name phpfpm -v $(pwd):/var/www/html -p 3000:3000 nanoninja/php-fpm php -S="0.0.0.0:3000" -t="/var/www/html"
But when I try to run the same image with docker-compose.yml file, I don't get a connection to PHP.
Here is my very simple docker-compose.yml file:
version: '3'
services:
php:
image: nanoninja/php-fpm:8.1
restart: always
ports:
- 3000:9000
stdin_open: true
tty: true
I'm not using a Dockerfile.
Question: How to run PHP without Nginx using only docker-compose.yml file?
Image link: https://github.com/nanoninja/php-fpm
The docker-compose file equivalent to your docker container run command would be something like
version: "3"
services:
php:
image: nanoninja/php-fpm:8.1
container_name: phpfpm
restart: always
ports:
- 3000:3000
command: php -S="0.0.0.0:3000" -t="/var/www/html"
volumes:
- ./:/var/www/html
The -v option becomes the volumes: section. The part after the image name becomes the command:. The -p option becomes the ports: section. --name becomes container_name:, etc.

How to access another containers while running app in `nginx` container in Docker?

I am dockerizing laravel (lumen) app locally on Mac computer.
docker-compose.yml:
version: "3.9"
services:
# LibreOffice Service
libreoffice:
image: lscr.io/linuxserver/libreoffice:latest
container_name: libreoffice
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/London
volumes:
- ./:/home
ports:
- "3000:3000"
restart: unless-stopped
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8080:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
As you see in yml file I am running my app in nginx container and everything works fine.
But when I try to run command:
docker exec libreoffice soffice --headless --invisible --convert-to pdf --outdir "home/public/tmp" "home/public/tmp/hi.docx"
in my application, it throws the following error:
sh: 1: docker: not found
After wasting days I thing that it is trying to find docker in nginx container not on my local computer. Means all other services I have defined in docker-compose.yml file can not be accessed in my application because my application = nginx container. But why? What should I do then? How should I create environment to access another services in my application?
MY BIG QUESTION
Why it is even running whole app in container? When I run app with nginx, then my app breaks the connection with my local environment and trying to find all other containers in nginx container. For example if I need to convert some files and for that convertation I need libreoffice service to run in background. And when I try to connect it with soffice --headless --invisible --convert-to pdf --outdir command it throws an error like:
sh: 1: soffice: not found
Because it is looking for soffice in nginx container not in my local docker at all. If that is the case then How can I even run my application with nginx? Do I need to run all other containers in nginx container? How is it possible?
After making some more research I have found that it is impossible to access to the container from another container and run some command inside.
Some solutions to that problem:
Use service's REST API to connect.
If your service doesn't have REST API to access and run it
Removing libreoffice service as container and installing it to php container with linux command in Dockerfile:
RUN apt-get update && apt-get install -y libreoffice
Command can be run remotely using ssh. Check this topic (I don't recommend)

WSL2 docker-compose - unable to prepare context

I am using the Docker Engine running on WSL2 which is running on Windows 10 computer. My goal is to create a service using the Docker-compose that uses the php:fpm image and install the mysqli extension to it. Here is my docker-compose.yaml
version: "3"
services:
nginx:
image: "nginx"
restart: 'always'
ports:
- '3030:80'
volumes:
- ./src:/src
- ./config/site.conf:/etc/nginx/conf.d/default.conf
networks:
- code-network
php:
build:
context: .
dockerfile: Dockerfile
image: php:fpm
volumes:
- ./src:/src
networks:
- code-network
mariadb:
image: "mariadb:10.3.24"
restart: 'always'
volumes:
- "/var/lib/mysql/data:/data"
- "/var/lib/mysql/logs:/logs"
- /var/docker/mariadb/conf:/etc/mysql
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "T05CNCitk2020#"
MYSQL_USER: "user"
MYSQL_PASSWORD: "Heslo123"
networks:
- code-network
networks:
code-network:
driver: bridge
And here is my Dockerfile:
FROM php:fpm
RUN docker-php-ext-install mysqli
When I run the command docker-compose up --build which forces the container to rebuild. I ran into the following problem:
Building php
unable to prepare context: path "\\\\?\\\\\\wsl$\\Ubuntu-20.04\\home\\vendasky\\Projects\\sql-gui" not found
ERROR: Service 'php' failed to build : Build failed
I do not see the reason why the path should be wrong when all the files are located in the Linux subsystem. Any hints, how to solve this problem?
are you runnning this with docker desktop for windows?
If thats the case try enabling the Docker Compose V2 option under the experimental settings. This should fix your problem.
Docker is unable to find the path to that project, map your ubuntu correctly so it can easily locate the project, that should fix your issue.

How to build a docker image with PHP-fpm and nginx using docker-compose

I'm trying to deploy my dockerized application using docker-compose. I have an application service running with php-fpm and an nginx service running with the latest nginx image. Now I would like to build an image that can run my PHP application using Nginx. I'm not sure how to accomplish that. I have seen some images that are pre build for it, but nothing seemed promising.
Would the correct way to do it be to install nginx on a php based imaged and use that? I'm not sure.
version: "3"
services:
application:
networks:
- mynetwork
container_name: the-application
image: the-application:latest
build:
context: ./
dockerfile: ./docker/application.dockerfile
volumes:
- ./backend/:/backend
backend-server:
container_name: the-backend-server
image: the-backend-server:latest
build:
context: ./
dockerfile: ./docker/server.dockerfile
volumes:
- ./backend/:/backend
- ./configs/nginx/nginx.backend-prod.conf:/etc/nginx/conf.d/default.conf
ports:
- 80:80
networks:
- mynetwork
networks:
mynetwork:

Categories