How to connect local redis to docker container using docker compose - docker

I am facing an issue with connect local redis with docker container, this is my docker compose file.
version: "3"
services:
test:
build: .
stdin_open: true
tty: true
command: nodemon --delay 6 index.js
volumes:
- .:/opt/test
ports:
- "5007:5007"
links:
- redis
redis:
image: redis:latest
container_name: qbo_redis
restart: always
ports:
- "6379:6379"
But it is not working.
Getting error
bash
TI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"3ed84a23c52d\": executable file not found in $PATH": unknown
If i remove the redis entries from docker-compose.yml file, its working without any error.

docker ps -q returns a list of containers and cannot be used to access the shell. Use docker ps -ql to work with the last container created.
redis images don't contain Bash. They're based on Alpine Linux, but can you use /bin/sh. Try this way:
docker exec -it qbo_redis /bin/sh
or
docker exec -it $(docker ps -ql) /bin/sh

Related

How to get a bash terminal in an IPFS docker container

I am running IPFS with docker. The docker-compose.yml is as follows
#version of docker compose
version: '3'
services:
ipfshost:
image: ipfs/kubo:latest
container_name: ipfs
env_file:
- .env
ports:
- 4001:4001
- 4001:4001/udp
- 8081:8080
- 5001:5001
volumes:
- ./ipfs_staging:/export
- ./ipfs_data:/data/ipfs
- ./config:/data/ipfs/config
volumes:
ipfs_staging:
external: true
ipfs_data:
external: true
Currently the only way I can find to run CLI commands is using docker exec ipfs ipfs [command]. It's annoying to have to prepend docker exec ipfs to every command, but docker exec -it ipfs bash does not load a terminal.
The error is:
OCI runtime exec failed: exec failed: unable to start container process: exec: "bash": executable file not found in $PATH: unknown
I also tried docker exec -it ipfs /bin/bash
The resulting error is:
OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
Is there a fairly straightforward way to solve this? The errors seem to indicate there is no bash software in the docker container.

Docker ps doesn't show containers created/runing with docker-compose

I'm trying to understand why I can't see containers created with docker-compose up -d using docker ps. If I go to the folder where is the docker-compose.yaml located and run docker-compose ps I can see the container runing. I did the same on windows because i'm using ubuntu and it works as expected, I can see the container just runing docker ps. Could anyone give me a hint about this behavior, please? Thanks in advance.
Environment:
Docker version 20.10.17, build 100c701
docker-compose version 1.25.0, build unknown
Ubuntu 20.04.4 LTS
in my terminal i see this output:
/GIT/project$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
/GIT/project$ cd scripts/
/GIT/project/scripts$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
/GIT/project/scripts$ docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------
scripts_db_1 docker-entrypoint.sh --def ... Up 0.0.0.0:3306->3306/tcp,:::3306->3306/tcp,
33060/tcp
/GIT/project/scripts$
docker-compose.yaml
version: '3.3'
services:
db:
image: mysql:5.7
# NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
# (this is just an example, not intended to be a production configuration)
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
# <Port exposed> : < MySQL Port running inside container>
- 3306:3306
expose:
# Opens port 3306 on the container
- 3306
# Where our data will be persisted
volumes:
- treip:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: changeit
MYSQL_DATABASE: treip
volumes:
treip:
I executed the container with sudo and the problem was solve. now the container apear using docker ps, so instead of docker-compose up I executed it with sudo sudo docker-compose up . Sorry, my bad.

How to test extra_hosts configuration?

How can I check if my extra_hosts configuration is working?
version: '3.5'
services:
nginx:
image: nginx:stable
extra_hosts:
- "host.docker.internal:host-gateway"
I tried docker exec nginx /bin/sh -c 'ping host.docker.internal'
but got /bin/sh: 1: ping: not found
Is there some kind of ping alternative available in the nginx docker image?
Testing on Ubuntu 20.04.3 LTS host, with docker version 20.10.11 and docker-compose version 1.29.2.
nginx image does not come with ping command, you can add a busybox to test in and out:
cat << EOF > docker-compose.yaml
version: '3.5'
services:
nginx:
image: nginx:stable
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- 8080:80
busybox:
image: busybox
extra_hosts:
- "host.docker.internal:host-gateway"
command: ash -c 'sleep 3600'
EOF
docker-compose up -d
docker-compose exec busybox ping host.docker.internal
docker-compose exec busybox wget -qO- nginx
docker-compose exec busybox wget -qO- host.docker.internal:8080
docker-compose down
Always use sidecar container & do not overwhelm the main image:
k8s community provides a good image for network debugging which includes almost all famous CLIs : dig, nslookup, ping,.etc
k8s.gcr.io/e2e-test-images/jessie-dnsutils:1.3
Use it the same way the busybox way explained by gohm'c

Trouble with exec command on mariadb container

I want to access the db directly through command prompt.
I run the command:
docker exec -it container_name -u user_name -p
Instead of a line asking me the user password I get the following error message:
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"-u\": executable file not found in $PATH": unknown
I've tried several other commands of the same type:
docker exec -it container_name -u -p
docker exec -it container_name -u user_name
docker exec -it container_name -u root
I don't use a Dockerfile but the image directly :
version: '3'
services:
frontend:
build: ./frontend
volumes:
- ./frontend/:/app
ports:
- ${PORT_FRONTEND}:${PORT_FRONTEND}
container_name: dev_frontend
database:
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD}
ports:
- "${PORT_MARIADB}:${PORT_MARIADB}"
volumes:
- ./volumes/database/:/var/lib/mysql:rw
container_name: dev_mariadb
I use a .env file to store sensible data instead of placing them in the docker-compose.yml
If anyone has any idea on how to proceed to find the issue I'd be grateful.
Thanks!
Simply correct the command above with :
docker exec -it container_name mysql -u{username} -p{userpassword}

Interact with redis container started with docker compose

I have a docker compose file that links my server to a redis image:
version: '3'
services:
api:
build: .
command: npm run dev
environment:
NODE_ENV: development
volumes:
- .:/home/node/code
- /home/node/code/node_modules
- /home/node/code/build/Release
ports:
- "1389:1389"
depends_on:
- redis
redis:
image: redis:alpine
I am wondering how could I open a redis-cli against the Redis container started by docker-compose to directly modify ke/value pairs. I tried with docker attach but it does not open any shell.
Use docker exec -it your_container_name /bin/bash to enter into redis container, then execute redis-cli to modify key-value pair.
See https://docs.docker.com/engine/reference/commandline/exec/
Install the Redis CLI on your host. Edit the YAML file to publish Redis's port
services:
redis:
image: redis:alpine
ports: ["6379:6379"]
Then run docker-compose up to redeploy the container, and you can run redis-cli from the host without needing to directly interact with Docker.
Using /bin/bash as the command (as suggested in the accepted solution) doesn't work for me with the latest redis:alpine image on Linux.
Instead, this worked:
docker exec -it your_container_name redis-cli

Resources