What is the difference between Docker Unix socket on ubuntu vs alpine? - docker

I am running through a problem where I can't mount Unix docker socket to an alpine container but works with ubuntu container.
docker-compose using alpine image
version: '3.8'
services:
cluster:
image: alpine
tty: true
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/usr/bin/docker:/usr/bin/docker"
running docker command in the alpine container:
/ # docker --version
sh: docker: not found
docker-compose using ubuntu image
version: '3.8'
services:
cluster:
image: ubuntu:20.04
tty: true
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/usr/bin/docker:/usr/bin/docker"
running docker command in the ubuntu container:
root#5f30b4143c43:/# docker --version
Docker version 20.10.12, build e91ed57
I don't get why I can access my host docker env using the ubuntu container but not with the alpine one? is there anything missing in the configuration?

Your error has nothing to do with the socket:
/ # docker --version
sh: docker: not found
You're seeing this because you're trying to run a binary compiled for glibc platform, while Alpine is built using MUSL libc.
You would need to install a version of the docker client built specifically for use under Alpine (or just pick almost any other image).

Related

In Docker Compose file, how to enable GPU in service build instructions?

I am trying to build service from docker file when start docker compose. The docker-compose.yml looks like:
version: '3'
services:
app:
build:
context: .
shm_size: 4gb
# ...
The build process need to enable GPU. I know how to enable GPU in deploy according to this blog. But it seems docker compose file build do not support GPU.
I think, I have read two different method.
The simple, try that:
https://docs.docker.com/compose/gpu-support/
https://www.tremplin-numerique.org/en/how-to-run-compose-docker-containers-with-gpu-access
services:
test:
image: nvidia/cuda:10.2-base
command: nvidia-smi
runtime: nvidia
The complex,
It run a docker via a run.
Then via docker compose, it connect to its docker.
In this method, it describes all steps.
https://dinhanhthi.com/docker-gpu/
docker run \
--gpus all\
--name docker_thi_test\
--rm\
-v abc:abc\
-p 8888:8888
Yaml
version: '2'
services:
jupyter:
container_name: 'docker_thi_test'
build: .
volumes:
- ./notebooks:/tf/notebooks
ports:
- 8888:8888
environment:
- NVIDIA_VISIBLE_DEVICES=0
- PASSWORD=12345

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

How to use docker command in container?

I want to use docker command in container on the centos 7.8
I already installed docker at the centos and want to use docker command in the docker container.
So, I added volume in the docker compose file like below.
services:
test_container:
container_name: test
image: app:${DOCKER_TAG}
privileged: true
ports:
- 80:3000
environment:
ENVIRONMENT: develop
volumes:
- /var/lib/docker:/var/lib/docker
- /lib/systemd/system/docker.service:/lib/systemd/system/docker.service
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /etc/sysconfig/docker:/etc/sysconfig/docker
But when I run docker compose and use docker command in the container, it shows like this.
You don't have either docker-client or docker-client-latest installed. Please install either one and retry.
How could I fix this? or How could I use the docker command in docker container?
Thank you for reading my questions.
In order to run docker in a docker container, you should use "DinD"( docker in docker ) with privileges. Something like this should work;
docker run --privileged -d docker:find
Another option - instead of starting “child” containers like DinD, it will start “sibling” containers.
docker run -v /var/run/docker.sock:/var/run/docker.sock \
-ti docker
For docker compose;
version: "2"
services:
docker-in-docker:
image: docker:dind
privileged: true
expose:
- 2375
- 2376
node1:
image: docker
links:
- docker-in-docker
environment:
DOCKER_HOST: tcp://docker-in-docker:2375
command: docker ps -a

docker-compose up not binding ports

/usr/local/bin/docker-compose up
I am using this command on Amazon Linux. It does not bind the ports, so I could not connect to the services running inside the container. The same configuration is working on a local development server. Not sure what I am missing.
[root#ip-10-0-1-42 ec2-user]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ec6320747ef3 d8bd4345ca7f "/bin/sh -c 'gulp bu…" 30 seconds ago Up 30 seconds vigilant_jackson
Here is the docker-compose.yml:
version: '2'
services:
web:
build: .
command: gulp serve
env_file:
- .env
volumes:
- .:/app/code
ports:
- "8050:8000"
- "8005:8005"
- "8888:8888"
npm -v 5.6.0
docker -v Docker version 18.06.1-ce, build e68fc7a215d7133c34aa18e3b72b4a21fd0c6136
Are you sure the ports are not published?
Use docker inspect, I would guess that they are published. If this is the case, then my guess is that as you are on AWS, you are not ssh-ing to the opened port (8050, 8005, 8888 are ports of the AWS linux instance, if I got your question correctly).

Resources