start node process from docker-compose - docker

I have the following docker-compose file:
version: '3'
services:
frontend:
image: node:9
working_dir: /dist
command: PORT=8000 node /static/index.js
volumes:
- ./dist:/static
ports:
- "8000:8000"
environment:
NODE_ENV: ${NODE_ENV}
But when I run it, I get this error:
Cannot start service frontend: OCI runtime create failed:
container_linux.go:296: starting container process caused "exec:
\"PORT=8000\": executable file not found in $PATH": unknown

You don't need the command to publish the port or make accessible by the host.
Only clause ports is enough.
ports:
- 8000:8000
note the double quote.
If you need a environment variable, can use the clause environment
frontend:
environment:
- PORT=8000

Related

Docker Compose Failing for command

Dockerfile:
FROM hseeberger/scala-sbt:8u222_1.3.5_2.13.1
WORKDIR /code/SimpleStocks
COPY ./SimpleStocks .
RUN sbt dist
WORKDIR /code/SimpleStocks/target/universal
RUN unzip simplestocks-0.0.1.zip
WORKDIR /code/SimpleStocks/target/universal/simplestocks-0.0.1
CMD ["bin/simplestocks"]
docker-compose.yml:
version: "3.7"
services:
app:
container_name: simple-stocks
image: simple-stocks:1.0.0
build: .
ports:
- '9000:9000'
volumes:
- .:/code
links:
- pgdb1
pgdb1:
image: postgres
environment:
POSTGRES_DB: simple_stocks
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- pgdb1data:/var/lib/postgresql/data/
- ./docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
ports:
- '5432:5432'
volumes:
pgdb1data:
When I manually run simple-stocks container using docker run -it {imageId}, I am able to run it successfully; but, on doing docker compose up I am receiving:
Error response from daemon: OCI runtime create failed:
container_linux.go:380: starting container process caused: exec:
"bin/simplestocks": stat bin/simplestocks: no such file or directory:
unknown
Your Dockerfile is building the application in /code/SimpleStocks/target/universal/simplestocks-0.0.1, but then your Compose file bind-mounts a host directory over /code, which hides everything the Dockerfile does. The bind mount is unnecessary and deleting it will resolve this issue.
Bind-mounting a host directory over your entire built application usually is not a best practice. I most often see it trying to convince Docker to emulate a local development environment, but even that approach doesn't make sense for a compiled language like Scala.
You can safely remove the volumes: block. The obsolete links: can also be removed. You don't need to manually specify container_name:, nor do you need to specify both build: and image: unless you're planning to push the built image to a registry. That would reduce the Compose setup to just:
version: '3.8'
services:
app:
build: .
ports:
- '9000:9000'
pgdb1: (as in the question originally)
volumes:
pgdb1data:

OCI runtime create failed: container_linux.go:380: starting container process caused: exec: no such file or directory: unknown

I want to run a docker-compose file but I keep getting
ERROR: for service2 Cannot start service service2: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "./wait.sh": stat ./wait.sh: no such file or directory: unknown
and my docker-compose file is
version: "3"
services:
service1:
restart: always
container_name: service1
build: ./service1
environment:
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
service2:
container_name: service2
build: ./service2
environment:
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
depends_on:
- service1
restart: "no"
volumes:
- ./data.csv:/data.csv
command: ["./wait.sh", "service1:5432", "--", "python", "./service2.py"]
but if I go and try to build Dockerfile for service2 everything is ok and I can run wait.sh.
Here's Dockerfile for service2:
FROM python:latest
WORKDIR /service2
RUN pip install psycopg2==2.8.6
COPY ./service2.py .
COPY ./wait.sh ./wait.sh
RUN chmod +x ./wait.sh
I completely don't get what's wrong especially because when I first ran docker-compose up the same error occured. But after that error did not occur for several times I ran docker-compose up and now again it doesn't work though I run the same docker-compose file.
wait.sh was taken from here
service2.py connects to db and writes from data.scv but since it doesn't even run that should not be the problem.

docker-compose on virtualbox machine - ./wait-for-it.sh: no such file of directory: unknown

I created machine:
docker-machine create -v virtualbox docker-local
Switched to machine:
eval ($docker-machine env docker-local)
Now, Im trying to run docker-compose on it to serve my apps on this machine.
This are my files:
docker-compose.yml
version: "3"
services:
db:
image: mysql:5.7
container_name: db
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: 'test'
MYSQL_ROOT_PASSWORD: 'asdasd123'
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
app:
build:
context: .
dockerfile: ./dockerfiles/python/Dockerfile
container_name: app
volumes:
- ./app:/app
- static:/app/static
- media:/app/media
command: >
./wait-for-it.sh db:3306 --timeout=30 --strict -- ./run.sh
expose:
- "8000"
depends_on:
- db
nginx:
container_name: nginx
restart: always
build:
context: .
dockerfile: ./dockerfiles/nginx/Dockerfile
volumes:
- ./nginx:/etc/nginx/conf.d
- ./nginx_logs:/var/log/nginx
- ./nginx_html:/html
- ./ssl_cert:/etc/nginx/conf.d/certs/
- static:/static
- media:/media
ports:
- "1337:80"
- "443:443"
depends_on:
- app
volumes:
static:
media:
If i lauch this docker-compose.yml using docker-compose up everything works fine in local pc, however on virtualbox machine - error accured:
Creating db ... done
Creating app ... error
ERROR: for app Cannot start service app: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"./wait-for-it.sh\": stat ./wait-for-it.sh: no such file or directory": unknown
ERROR: for app Cannot start service app: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"./wait-for-it.sh\": stat ./wait-for-it.sh: no such file or directory": unknown
ERROR: Encountered errors while bringing up the project.
Why is this happening only on docker-machine? Why it has no access to wait-for-it.sh here?

passing multiple .yml files to docker-compose

Docker noob here.
I have two files docker-compose.build.yml and docker-compose.up.yml in my docker folder. Following are the contents of both files..
docker-compose.build.yml
version: "3"
services:
base:
build:
context: ../
dockerfile: ./docker/Dockerfile.base
args:
DEBUG: "true"
image: ottertune-base
labels:
NAME: "ottertune-base"
web:
build:
context: ../
dockerfile: ./docker/Dockerfile.web
image: ottertune-web
depends_on:
- base
labels:
NAME: "ottertune-web"
volumes:
- ../server:/app
driver:
build:
context: ../
dockerfile: ./docker/Dockerfile.driver
image: ottertune-driver
depends_on:
- base
labels:
NAME: "ottertune-driver"
docker-compose.up.yml
version: "3"
services:
web:
image: ottertune-web
container_name: web
expose:
- "8000"
ports:
- "8000:8000"
links:
- backend
- rabbitmq
depends_on:
- backend
- rabbitmq
environment:
DEBUG: 'true'
ADMIN_PASSWORD: 'changeme'
BACKEND: 'postgresql'
DB_NAME: 'ottertune'
DB_USER: 'postgres'
DB_PASSWORD: 'ottertune'
DB_HOST: 'backend'
DB_PORT: '5432'
DB_OPTS: '{}'
MAX_DB_CONN_ATTEMPTS: 30
RABBITMQ_HOST: 'rabbitmq'
working_dir: /app/website
entrypoint: ./start.sh
labels:
NAME: "ottertune-web"
networks:
- ottertune-net
driver:
image: ottertune-driver
container_name: driver
depends_on:
- web
environment:
DEBUG: 'true'
working_dir: /app/driver
labels:
NAME: "ottertune-driver"
networks:
- ottertune-net
rabbitmq:
image: "rabbitmq:3-management"
container_name: rabbitmq
restart: always
hostname: "rabbitmq"
environment:
RABBITMQ_DEFAULT_USER: "guest"
RABBITMQ_DEFAULT_PASS: "guest"
RABBITMQ_DEFAULT_VHOST: "/"
expose:
- "15672"
- "5672"
ports:
- "15673:15672"
- "5673:5672"
labels:
NAME: "rabbitmq"
networks:
- ottertune-net
backend:
container_name: backend
restart: always
image: postgres:9.6
environment:
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'ottertune'
POSTGRES_DB: 'ottertune'
expose:
- "5432"
ports:
- "5432:5432"
labels:
NAME: "ottertune-backend"
networks:
- ottertune-net
networks:
ottertune-net:
driver: bridge
Nothing wrong with the dockerfiles, i just have a few doubts about this approach.
What purpose does having multiple files serve instead of just one docker-compose.yml?
How does docker-compose work when used with multiple files?
When i do docker-compose -f docker-compose.build.yml build --no-cache
Building base
Step 1/1 : FROM ubuntu:18.04
---> 775349758637
[Warning] One or more build-args [DEBUG] were not consumed
Successfully built 775349758637
Successfully tagged ottertune-base:latest
Building web
Step 1/1 : FROM ottertune-base
---> 775349758637
Successfully built 775349758637
Successfully tagged ottertune-web:latest
Building driver
Step 1/1 : FROM ottertune-base
---> 775349758637
Successfully built 775349758637
Successfully tagged ottertune-driver:latest
and then docker-compose up i get the error
rabbitmq is up-to-date
backend is up-to-date Starting web ... error
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:346:
starting container process caused "exec: \"./start.sh\": stat ./start.sh: no such file or
directory": unknown
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:346:
starting container process caused "exec: \"./start.sh\": stat ./start.sh: no such file or
directory": unknown
ERROR: Encountered errors while bringing up the project.
this entrypoint start.sh is defined in the docker-compose.up.yml file which I didn't pass as an argument to
docker-compose build
So, why is the docker-compose up trying to run this entrypoint from a yml file which is not even passed during build? Really confused on this and didn't find much about it on google and stackoverflow.
If you docker-compose -f a.yml -f b.yml ..., Docker Compose merges the two YAML files. If you look at the two files you've posted, one has all of the run-time settings (ports:, environment:, ...), and if you happened to have the images already it would be enough to run the application. The second only has build-time settings (build:), but requires the source tree checked out locally to be able to run.
You probably need to specify both files on every docker-compose invocation
docker-compose -f docker-compose.build.yml -f docker-compose.up.yml up --build
It does seem like the author of these files intended for them to be run separately
docker-compose -f docker-compose.build.yml build
docker-compose -f docker-compose.up.yml up
but note that some of the run-time options in the build file, like volumes: to hide the application built into the image, will never take effect.
(You should be able to delete a large number of settings in the "up" YAML file that either duplicate what's in the image or that Docker Compose can provide for you: container_name:, expose:, links:, working_dir:, entrypoint:, networks:, and (probably) labels: are all unnecessary and can be deleted.)
What purpose does having multiple files serve instead of just one docker-compose.yml?
You can share configuration across environments. For example, I keep the common configuration such as the network and server in a docker-compose.yml. I keep my development environment specifics such as a server with automatic reload and debugging enabled in a docker-compose.override.yml. I keep the production-specific configs in a docker-compose.prod.yml. Then I can run docker-compose up --build for my development environment (Docker Compose uses docker-compose.yml and docker-compose.override.yml by default). And I can run my prod environment with docker-compose -f docker-compose.yml -f docker-compose.prod.yml up --build. You can read about this in the dedicated docs page.
How does docker-compose work when used with multiple files?
It takes the first file as the base file, and adds or replaces configs from subsequent files ot the base file. See the relevant docs.
When i do docker-compose -f docker-compose.build.yml build --no-cache ...
As for your last question, I can't really tell by what I've seen. But unlike Dockerfiles which need two commands (docker build and docker run), docker-compose only needs one. So when you do docker-compose up, it looks for a file named docker-compose.yml (and also docker-compose.override.yml if it's present).

Docker compose run throws error on entrypoint

Running the following cmd:
docker-compose up -d
Throws the following error:
ERROR: for ubuntu_caddy_1 Cannot start service caddy: oci runtime error: container_linux.go:247: starting container process caused "exec: \"./caddy\": stat ./caddy: no such file or directory"
Here is docker-compose.yml file
services:
caddy:
image: abiosoft/caddy
ports:
- "80:80"
- "443:443"
- "2015:2015"
volumes:
- "./caddy-data:/root/.caddy"
- "./config:/etc/caddy"
- "./config/Caddyfile:/etc/Caddyfile"
entrypoint:
- ./caddy
- "-conf"
- /etc/Caddyfile
- "-agree"
- "-log=stdout"
- "-port=443"
restart: "on-failure: 10"
user: root
version: "2"
Any idea on what I would be missing here?
In the abiosoft/caddy Dockerfile, the standard entrypoint is ENTRYPOINT ["/bin/parent", "caddy"] (link here).
So I think that you must change ./caddy in your entrypoint by /bin/parent caddy.
I also think that you don't have to overwrite the default entrypoint, you just have to specify your args to caddy by overwriting the default command (which is CMD ["--conf", "/etc/Caddyfile", "--log", "stdout", "--agree=$ACME_AGREE"]).
So you end up with command: -conf /etc/Caddyfile -agree -log=stdout -port=443.

Resources