docker-compose.yml
version: '3'
services:
php-fpm:
image: php:8.1-fpm-alpine
command: whoami
docker compose output
$ docker-compose up
[+] Running 1/1
⠿ Container test-php-fpm-1 Recreated 0.1s
Attaching to test-php-fpm-1
test-php-fpm-1 | root
test-php-fpm-1 exited with code 0
tested on playground:
https://labs.play-with-docker.com/
version: '3'
services:
php-fpm:
image: php:8.1-fpm-alpine
command: whoami
tty: true
restart: always
# restart: unless-stopped
This restart the container constantly.
I need to install pdo_mysql
command: sh -c "docker-php-ext-install pdo pdo_mysql"
I don't find anything about this problem
Related
If I build from the Dockerfile I can run the docker run IMAGE_ID /bin/bash and browse the container.
But if I run docker-compose up -d from docker-compose.yml and run docker attach, it doesn't respond, it stays still in the container terminal and sometimes leaves the container terminal alone
Follow my docker files
Dockerfile
FROM nginx:1.21.6
EXPOSE 80
WORKDIR /etc/nginx
ENTRYPOINT /bin/bash
docker-compose.yml
version: "3.8"
services:
reverse:
build:
dockerfile: Dockerfile
context: ./nginx/docker
image: reverse/nginx
container_name: reverse
ports:
- 80:80
- 443:443
volumes:
- ./nginx:/etc/nginx
tty: true
To be able to provide interactive input after attaching you also need to set stdin_open: true in the docker-compose.yml:
services:
reverse:
# ...
tty: true
stdin_open: true
But depending on what you want to achieve with this probably a better solution would be
docker-compose exec reverse /bin/bash or
docker-compose run reverse /bin/bash.
I have a docker-compose.yml file that starts two services: amazon/dynamodb-local on 8000 port and django-service. django-service runs tests that are dependent on dynamodb-local.
Here is working docker-compose.yml:
version: '3.8'
services:
dynamodb-local:
image: "amazon/dynamodb-local:latest"
container_name: dynamodb-local
ports:
- "8000:8000"
django-service:
depends_on:
- dynamodb-local
image: django-service
build:
dockerfile: Dockerfile
context: .
env_file:
- envs/tests.env
volumes:
- ./:/app
command: sh -c 'cd /app && pytest tests/integration/ -vv'
Now I need to run this without docker-compose, only using docker itself. I try to do following:
docker network create -d bridge net // create a network for dynamodb-local and django-service
docker run --network=net --rm -p 8000:8000 -d amazon/dynamodb-local:latest // run cont. att. to network
docker run --network=net --rm --env-file ./envs/tests.env -v `pwd`:/app django-service /bin/sh -c 'env && cd /app && pytest tests/integration -vv'
I can see that both services start, but I can't connect to the dynamo-db.
Where is the problem? Any comment or help is appreciated!
Through the docker-compose.yml, the amazon/dynamodb-local container has a name defined (container_name: dynamodb-local, If we do not set this property, docker-compose will use the service's name as container name). This enables other containers in the same network to address the container through its name.
In the docker-run command, we do not set an explicit container name. We can set an explicit container name by executing docker run ... --name dynamodb-local .... More details can be found in the corresponding docker run documentation.
I'm new to Docker and having trouble running the docker image https://github.com/mpolden/echoip#docker-image. What am I doing wrong? Any help would be greatly appreciated!
$ docker run mpolden/echoip -a ./GeoLite2-ASN.mmdb -c ./GeoLite2-City.mmdb -f ./GeoLite2-Country.mmdb
echoip: open ./GeoLite2-Country.mmdb: no such file or directory
The files are in the same directory. To test on your end, download the files: GeoLite2-ASN.mmdb, GeoLite2-City.mmdb, GeoLite2-Country.mmdb: https://gofile.io/d/G4i6hb
Having a docker-compose.yml would make this much easier to run:
version: "3.7"
services:
echoip:
image: mpolden/echoip
command: "echoip -a ./GeoLite2-ASN.mmdb -c ./GeoLite2-City.mmdb -f ./GeoLite2-Country.mmdb"
ports:
- "8080:8080"
restart: unless-stopped
The files are in the same directory
Docker containers cannot access the host filesystem unless it is mounted as a volume. For example, you could mount the current directory to /data in the container...
docker run --rm -v "${PWD}:/data" -p 8080:8080 mpolden/echoip \
-a /data/GeoLite2-ASN.mmdb \
-c /data/GeoLite2-City.mmdb \
-f /data/GeoLite2-Country.mmdb \
-l 0.0.0.0:8080
A Docker Compose config might look like this
version: "3.8"
services:
echoip:
image: mpolden/echoip
command: >
-l 0.0.0.0:8080
-a /data/GeoLite2-ASN.mmdb
-c /data/GeoLite2-City.mmdb
-f /data/GeoLite2-Country.mmdb
ports:
- "8080:8080"
volumes:
- "./:/data"
restart: unless-stopped
I wrote a simple docker-compose.yml as bellow,
version: '3'
services:
ubuntu:
container_name: ubuntu
image: ubuntu
debian:
container_name: debian
image: debian
then ran
$ docker-compose up -d
finally I got two containers with exited status.
even I typed
$ docker start <container_id>
trying to make containers running, but still fail.
Anyone tell me how to fix my yaml file, to make this two containers run with 'docker-compose up -d' ?
The entrypoint and command for these 2 docker images ubuntu and debian will not do anything that keep the container running.
In case you want them to keep running, you can modify your docker-compose file like this
version: '3'
services:
ubuntu:
container_name: ubuntu
image: ubuntu
entrypoint:
- bash
- -c
command:
- |
tail -f /dev/null
debian:
container_name: debian
image: debian
entrypoint:
- bash
- -c
command:
- |
tail -f /dev/null
Here is my docker-compose.yml:
version: "3"
services:
test123:
build: .
container_name: "test123"
My Dockerfile:
FROM alpine:3.9
CMD ["/bin/sh"]
When I run:
docker run -it alpine:3.9
It works fine. But when I run from docker-compose:
docker-compose up -d
The container's status is always: Exited (0)
Any idea?
Your container starts and exits immediately because /bin/sh stops. This is how containers work. When their PID 1 stops, they exit. So, in order to prevent sh from exiting, you have to use:
tty: true
stdin_open: true
These options are the equivalent -it that you already use in your docker run ... command.
from the docs:
--tty , -t Allocate a pseudo-TTY
--interactive , -i Keep STDIN open even if not attached
Updated docker-compose.yml file:
version: "3"
services:
test123:
build: .
container_name: "test123"
tty: true
stdin_open: true
No wonder your container exits (with status 0, which means success).
The container must keep running in order to stay alive, so the command that is run must never end. Here would be a workaround:
Dockerfile:
FROM alpine:3.9
CMD ["tail", "-f", "/dev/null"]
That way the container will always remain busy, until you stop it.