Unable to give network name in docker-compose - docker

I am trying to create a network in docker-compose.yml
version: "3.5"
networks:
frontend:
name: custom_frontend
driver: custom-driver-1
it is giving error : ERROR: The Compose file './docker-compose.yml' is invalid because:
networks.frontend value Additional properties are not allowed ('name' was unexpected)
Please help
docker-compose version 1.17.1, build unknown

The compose file was fine. But as jonrsharpe mentioned, your docker-compose is not support version 3.5.
The releases page
You can run the following commands to upgrade docker-compose to 1.28.5.
curl -L https://github.com/docker/compose/releases/download/1.28.5/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
(The commands were copied from the releases page)
After upgrade, you can run docker-compose -f <your-compose-file> config to check whether the compose file is valid. If your compose file is valid it'll just print it out.

Related

Build args not passing from docker-compoes.yml to Dockerfile

My docker-compose.yml:
version: "3.8"
services:
web:
build:
context: .
args:
file_url: 'some-url'
My Dockerfile:
FROM ruby:2.7.4-bullseye
ARG file_url
RUN curl $file_url -L -o "file"
When I run:
docker-compose up --build
I expect Docker'd build and start my containers. But instead, I got:
Step 4/12 : RUN curl $file_url -L -o "file"
---> Running in 59696c6274c7
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
So obviously the build args are not passing to Dockerfile. I've read a lot of similar threads on Stackoverflow but couldn't figure out what went wrong.
One more thing. I can actually build the containers with docker-compose build web just fine. It's just when I run docker-compose up --build or docker-compose up the error occurred.
The variable is not passed correctly in your dockerfile.
see this for variable calls inside dockerfile: https://docs.docker.com/engine/reference/builder/
Ideally it's contained inside ${variable_name} .
this line RUN curl $file_url -L -o "file needs rectification.
In your Dockerfile change $file_url to ${file_url}

ash shell command not running while building image but in the container it works fine

I have a docker-compose.yml containing like this:
version: '3.9'
services:
n2:
build: .
restart: always
volumes:
db_data: {}
And Dockerfile like this:
from nginx:stable-alpine
add cm.ash /root
run chmod +x /root/cm.ash
run /root/cm.ash
And this is cm.ash commands:
#!/bin/ash
nginx -s reload
The issue is when I run docker-compose to build, I get this error:
2021/03/07 04:18:35 [notice] 8#8: signal process started 2021/03/07
04:18:35 [error] 8#8: open() "/var/run/nginx.pid" failed (2: No such
file or directory) nginx: [error] open() "/var/run/nginx.pid" failed
(2: No such file or directory) The command '/bin/sh -c /root/cm.ash'
returned a non-zero code: 1
While if I comment lines add cm.ash /root, run chmod +x /root/cm.ash and run /root/cm.ash in Dockerfile, and then I exec container with ash then run command nginx -s reload, it works fine.
Why does this happen and what is the reason of this behavior?
I have seen similar behavior between bash and dash, that I resolve it by adding a bash file into the image to run commands on behalf of bash shell to get my results and it works fine, but I'm not sure about the reason of this behavior in dash.
During build there is no nginx daemon running in the build container, so you can not connect to the daemon and tell him to reload.
This also means that you don't need to reload since nothing is loaded at this point.
When you start container from the final image, than the daemon (which is the entry point for the ngingx image, will start and you will be able to connect to the PID of the running instance to tell it to reload.

docker-compose named volume with one file: ERROR: Cannot create container for service, source is not directory

I am trying to make the binary file /bin/wkhtmltopdf from the container wkhtmltopdf available in the web container. I try to achieve this with a named volume.
I have the following docker container setup in my docker-compose.yml:
services:
web:
image: php:7.4-apache
command: sh -c "mkdir -p /usr/local/bin && touch /usr/local/bin/wkhtmltopdf"
entrypoint: sh -c "exec 'apache2-foreground'"
volumes:
- wkhtmltopdfvol:/usr/local/bin/wkhtmltopdf
wkhtmltopdf:
image: madnight/docker-alpine-wkhtmltopdf
command: sh -c "touch /bin/wkhtmltopdf"
entrypoint: sh -c "tail -f /dev/null" # workaround to keep container running
volumes:
- wkhtmltopdfvol:/bin/wkhtmltopdf
volumes:
wkhtmltopdfvol:
However, I get the following error when running docker-compose up:
ERROR: for wkhtmltopdf Cannot create container for service wkhtmltopdf:
source /var/lib/docker/overlay2/42e7082b8024ae4ebb13a4f0003a9e17bc18b33ef0677431dd002da3c21dde88/merged/bin/wkhtmltopdf is not directory
.../bin/wkhtmltopdf is not directory
Does that mean that I can't share one file between containers but only directories through a named volume? How do I achieve this?
Edit: I also noticed that /usr/local/bin/wkhtmltopdf inside the web container is a directory and not a file as I expected.
It can be tricky to share binaries between containers like this. Volumes probably aren't the mechanism you're looking for.
If you look at the Docker Hub page for the php image you can see that php:7.4-apache is an alias for (currently) php:7.4.15-apache-buster, where "Buster" is the name of a Debian release. You can then search on https://packages.debian.org/ to discover that Debian has a prepackaged wkhtmltopdf package. You can install this using a custom Dockerfile:
FROM php:7.4-apache
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --assume-yes --no-install-recommends \
wkhtmltopdf
# COPY ...
# Base image provides EXPOSE, CMD
Then your docker-compose.yml file needs to build this image:
version: '3.8'
services:
web:
build: .
# no image:, volumes:, or command: override
Just in terms of the mechanics of sharing binaries like this, you can run into trouble where a binary needs a shared library that's not present in the target container. The apt-get install mechanism handles this for you. There are also potential troubles if a container has a different shared-library ecosystem (especially Alpine-based containers), or using host binaries from a different operating system.
The Compose file you show mixes several concepts in a way that doesn't really work. A named volume is always a directory, so trying to mount that over the /bin/wkhtmltopdf file in the second container causes the error you see. There's a dependency issue for which container starts up first and gets to create the volume. A container only runs a single command, and if you have both entrypoint: and command: then the command gets passed as extra arguments to the entrypoint (and if the entrypoint is an sh -c ... invocation, effectively ignored).
If you really wanted to try this approach, you should make web: {depends_on: [wkhtmltopdf]} to force the dependency order. The second container should mount the volume somewhere else, it probably shouldn't have an entrypoint:, and it should do something like command: cp -a /bin/wkhtmltopdf /export. (It will exit immediately once this cp finishes, but that shouldn't matter.) The first container can then mount the volume on, say, /usr/local/bin, and not specially set command: or entrypoint:. There will still be a minor race condition (you're not guaranteed the cp command will complete before Apache starts) but it probably wouldn't be a practical problem.

ERROR: Version in "./docker-compose.yml" is unsupported

I am running docker-compose build in a folder with the relevant docker files and yml files. I see the following error
root#ubuntu187_demo_2:~/IDOLDockerContainers_12.4.0_COMMON/basic-idol# docker-compose build
ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
The docker-compose.yml is as follows
# Basic IDOL container setup
# Uses nifi to ingest and index data into content
# Uses find to make search results available
# Default admin user is created for find in the community service
# - see community/run_community.sh for details
version: "3.7"
x-args-shared:
- &idol-version IDOL_VERSION=12.4.0 # version of IDOL components to use
# Change the IP to the address of an external IDOL LicenseServer instance
x-external-licenseserver-host: &external-licenseserver-host
- "idol-licenseserver:xx.xx.xx.xx"
# Shared volume configuration for nifi and view service - see volumes
x-idol-ingest-volume: &idol-ingest-volume
- idol-ingest-volume:/idol-ingest
#x-idol-categorisation-volume: &idol-categorisation-volume
# - idol-categorisation-volume:/idol-categorisation
# Shared volume in NiFi and View
# Any files dropped into this volume will be ingested and indexed
volumes:
idol-ingest-volume:
# idol-categorisation-volume:
services:
idol-content:
image: idol-compose/content
build:
context: ./content
args:
- *idol-version
extra_hosts: *external-licenseserver-host
ports:
- 9100:9100
docker-compose version
root#ubuntu18_demo_2:~/IDOLDockerContainers_12.4.0_COMMON/basic-idol# docker-compose -version
docker-compose version 1.17.1, build unknown
docker version
root#ubuntu18_demo_2:~/IDOLDockerContainers_12.4.0_COMMON/basic-idol# docker -v
Docker version 19.03.1, build 74b1e89
I can't change the version on the docker-compose.yml file.
I have resolved the issue using following steps
$ sudo apt-get remove docker-compose
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Your compose is too old, if you cannot change the version in compose, try to upgrade to latest docker-compose version
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Detail refers to this
The spec was updated in Compose v1.27 to merge the properties from version 2.x and 3.x compose files into a single format. The version property can still be included for legacy reasons but is no longer required and can be omitted if running the latest release of docker-compose.
The following script will update your installation on Ubuntu and solve the issue :
#!/bin/bash
sudo apt-get remove docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Using "sudo" the command works for me.
sudo docker-compose up
I did the following steps:
sudo apt-get remove docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
I hope this will resolve this issue.
Docker now officially supports compose so according to the documentation https://docs.docker.com/compose/install/compose-plugin/#install-using-the-repository use sudo apt-get install docker-compose-plugin then docker compose.
If you use sudo apt-get install docker-compose then docker-compose then you will end up with the older tool not supporting the newest format.

CircleCI './docker-compose.yml' service 'version' doesn't have any configuration options

Related, but not duplicated: Docker - docker-compose 'version' doesn't have any configuration options
I am currently using a v2 docker-compose.yml with the following circle.yml:
machine:
services:
- docker
test:
post:
- docker build --rm=false -t zurfyx/repo:$CIRCLE_SHA1 .
- docker-compose run web npm test
deployment:
hub:
branch: master
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
- docker push zurfyx/repo:$CIRCLE_SHA1
CircleCI gives the following output:
docker-compose run web npm test
ERROR: In file './docker-compose.yml' service 'version' doesn't have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.
docker-compose run web npm test returned exit code 1
I tried the following solutions that show up on a very recent CircleCI forum post, but I didn't manage to get rid of the problem.
Upgrading both docker and docker-compose to the latest version is required:
machine:
pre:
- curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0
- pip install --upgrade pip
- pip install docker-compose
services:
- docker
Why both?
Some say that upgrading docker-compose to the latest version by using pip is enough, but apparently is not (because the current Docker Engine CircleCI version does not support it, at least not anymore):
ERROR: The Docker Engine version is less than the minimum required by
Compose. Your current project requires a Docker Engine of version
1.10.0 or greater.
If you just upgrade Docker engine, it does not make any difference, since a higher docker-compose version is required to parse v2 YAML documents.

Resources