I'm trying to run my php website with nginx server as docker containers on a remote server via ssh connection using docker compose
I used this commanddocker-compose -H ssh://<username>#<**.***.**.***> up -d
and got this error
[+] Building 0.0s (0/0)
[+] Building 0.0s (0/0)
[+] Building 8.0s (2/2) FINISHED
=> ERROR [internal] load build definition from Dockerfile 5.0s
=> CANCELED [internal] load .dockerignore 5.0s
------
> [internal] load build definition from Dockerfile:
------
failed to dial gRPC: command [ssh -l username-- **.***.**.*** docker system dial-stdio] has exited with exit status 1, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=
My Dockerfile:
FROM php:8.0.2-fpm
RUN apt-get update && apt-get install -y \
git \
curl \
zip \
vim \
unzip
WORKDIR /var/www
My docker-compose.yml
version: '3.8'
services:
app:
build:
context: ./
dockerfile: Dockerfile
container_name: programwithgio-app
restart: always
working_dir: /var/www/
volumes:
- ../src:/var/www
nginx:
image: nginx:1.19-alpine
container_name: programwithgio-nginx
restart: always
ports:
- 8000:80
volumes:
- ../src:/var/www
- ./nginx:/etc/nginx/conf.d
Related
I have a PNPM workspace environment. I try to build one of my package using docker compose.
To do so, I have the following script in package.json file (in root folder):
"cluster:start": "pnpm exec ./docker/scripts/start-cluster.sh"
This is the ./docker/scripts/start-cluster.sh file:
#!/bin/bash
docker-compose up -d
This is my docker-compose.yaml file:
version: '3.8'
services:
frontend:
container_name: frontend
build:
context: ./docker
dockerfile: Dockerfile.frontend-dev
env_file:
- ./apps/frontend/.env.development
ports:
- 8080:8080
restart: always
networks:
- dashboard_network
networks:
dashboard_network:
driver: bridge
And this is my ./docker/Dockerfile.frontend-dev file:
FROM node:16
RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
WORKDIR /dashboard
COPY ../package.json ./
COPY ../apps/frontend/package.json ./apps/frontend/
RUN pnpm install
COPY ../ ./
CMD ["pnpm", "--filter", "frontend", "start"]
So when I run on root folder pnpm cluster:start I get an error:
=> ERROR [dashboard-frontend 4/7] COPY ../package.json ./ 0.0s
=> ERROR [dashboard-frontend 5/7] COPY ../apps/frontend/package.json ./apps/frontend/ 0.0s
------
> [dashboard-frontend 4/7] COPY ../package.json ./:
------
------
> [dashboard-frontend 5/7] COPY ../apps/frontend/package.json ./apps/frontend/:
------
failed to solve: failed to compute cache key: "/apps/frontend/package.json" not found: not found
Could anyone tell why?
This is the path to this error file: ROOT_FOLDER/apps/frontend/package.json
Short answer to "why": docker context.
This command is wrong:
COPY ../package.json ./
You cannot get "out" of the docker build context.
In your docker-compose.yml you define a context. That is a folder. When the build starts, the contents of that folder (with exceptions defined in .dockerignore) are sent to the docker daemon. And that is the set of file that your COPY commands can see. Nothing else. So the COPY does not work in your current folder, but on a copy of that folder that was sent to the docker daemon.
I have multiple Docker Containers (Server, Client, AI) running on the same Docker bridge. I want the AI to connect to the Server in order to exchange information with Socket.io.
However, when I try to connect the AI to to the Server via:
sio = socketio.Client()
def main():
sio.connect('http://localhost:4000')
sio.emit('ConnectAI', "TEST")
sio.wait()
print("Setting up Connection...")
time.sleep(10)
asyncio.run(main())
I get an Error saying
socketio.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=4000): Max retries exceeded with url: /socket.io/?transport=polling&EIO=4&t=1659336255.2636092 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f87b70dc7f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
I don't know why the connection gets refused. The machines run on the same network, they both use the same version of socketIO.
Here is my Docker-Compose file:
version: "3.9"
services:
client:
build:
context: ./client
dockerfile: Dockerfile
ports:
- "3000:3000"
server:
build:
context: ./server
dockerfile: Dockerfile
ports:
- "4000:4000"
ai:
build:
context: ./ai
dockerfile: Dockerfile
ports:
- "5000:5000"
And here is my Server Docker:
# Dockerfile
FROM node:14.20.0
WORKDIR /app
COPY . /app
RUN npm install
EXPOSE 4000
CMD npm start
And my AI Docker:
# Dockerfile
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
EXPOSE 5000
CMD python3 connection.py
I am on win home, using docker toolbox and getting this error:
make: /bin/sh: Operation not permitted make: *** [Makefile:243:
pdo.lo] Error 127 ERROR: Service 'php' failed to build: The command
'/bin/sh -c docker-php-ext-install pdo pdo_mysql' returned a non-zero
code: 2
php.dockerfile
FROM php:8.0.9-fpm-alpine
WORKDIR /var/www/html
COPY src .
RUN docker-php-ext-install pdo pdo_mysql
RUN addgroup -g 1000 laravel && adduser -G laravel -g laravel -s /bin/sh -D laravel
USER laravel
docker-compose.yml
version: "3.7"
services:
server:
image: nginx:stable-alpine
ports:
- 80:80
volumes:
- ./src:/var/www/html
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: dockerfiles/php.dockerfile
volumes:
- ./src:/var/www/html:delegated
mysql:
image: mysql:8.0
env_file:
- ./env/mysql.env
composer:
build:
context: ./dockerfiles
dockerfile: composer.dockerfile
volumes:
- ./src:/var/www/html
Any help or suggestion is greatly appreciated
I was facing the same issue. After updating php-fpm to a minor version up to 8.0.9. I couldn't build the image with Docker version 19.03.1.
But with Docker version 20.10.8 build the passes OK. You could also try to update Docker and try to build again. It might help you out.
FROM node:latest
WORKDIR /frontend/
ENV PATH /frontend/node_modules/.bin:$PATH
COPY package.json /frontend/package.json
COPY . /frontend/
RUN npm install --silent
RUN npm install react-scripts#3.0.1 -g --silent
CMD ["npm", "run", "start"]
This is my Dockerfile for the frontend of my project.
I put this as one of the services in my docker-compose.yml file, and when I run docker-compose up -d --build, it gives me
Step 6/8 : RUN npm install --silent
---> Running in 09a4f59a96fa
ERROR: Service 'frontend' failed to build: The command '/bin/sh -c npm install --silent' returned a non-zero code: 1
My docker-compose file looks like below for your reference:
# Docker Compose
version: '3.7'
services:
frontend:
container_name: frontend
build:
context: frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- '.:/frontend'
- '/frontend/node_modules'
backend:
build: ./backend
ports:
- "5000:5000"
volumes:
- .:/code
Thanks in advance
EDIT: Error in the frontend after build
For docker-compose, I think it should be like
- ./frontend/:/frontend'
as the build context is frontend.
Second, thing if you are using volume then why you are installing and copying code in Dockerfile? If you are using bind volume then remove these from your Dockerfile as these will be overridden from the host code.
COPY package.json /frontend/package.json
COPY . /frontend/
I've got the following dir tree:
project_root
|- build_script.sh
|- dir_1/Dockerfile and docker-compose.yml
|- tarball_dir/
I've got the build_script.sh which calls docker-compose like so:
docker-compose -f ./dir_1/docker-compose.yml build --build-arg BUILD_ID=$BUILD_ID dev
This is the Dockerfile:
FROM elixir:1.5.2
ARG BUILD_ID
ENV APP_HOME /app
RUN mkdir $APP_HOME
# Copy release tarball and unpack
~ ADD ../dir_1/${BUILD_ID}.tar.gz $APP_HOME/
CMD $APP_HOME/bin/my_app foreground
And this is the docker-compose-yml:
version: '2'
services:
common:
build:
context: .
dockerfile: ./Dockerfile
networks:
- default
dev:
extends:
service: common
env_file:
- ./dev.env
environment:
POSTGRES_HOST: "postgres.dev"
MIX_ENV: dev
ports:
- "4000:4000"
depends_on:
- postgres
I want to be able to ADD (so that it copies and unpacks the tarball) into the image. However, after trying endless combinations of Docker context directories and trying to include the tarball into the image, I always get one of two errors:
ERROR: Service 'dev' failed to build: ADD failed: Forbidden path outside the build context: ../tarball_dir/tarball.tar.gz ()
or
ERROR: Service 'dev' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder887135091/tarball_dir/tarball.tar.gz: no such file or directory
I would like to keep this directory structure, if possible. I've managed to build and run the container with the following command:
docker build \
--build-arg BUILD_ID=$BUILD_ID \
-t my_app:$BUILD_ID \
-f dir_1/Dockerfile .
docker run \
--network my_app_network \
--env-file ./dir_1/$ENV.env \
my_app:$BUILD_ID
But I can't reproduce this same behaviour using docker-compose no matter what.
I'm on Mac OS Sierra and I'm using Docker Edge Version 17.10.0-ce-mac36 (19824) Channel: edge a7c7e01149