Start Docker Daemon
docker daemon -g /u01/docker
Docker Info
[bu#bu ~]$ docker version
Client:
Version: 1.12.3
API version: 1.24
Go version: go1.6.3
Git commit: 6b644ec
Built:
OS/Arch: linux/amd64
Server:
Version: 1.12.3
API version: 1.24
Go version: go1.6.3
Git commit: 6b644ec
Built:
OS/Arch: linux/amd64
Dockerfile
FROM nginxmagento
MAINTAINER Bilal
ENTRYPOINT service ssh restart && service nginx restart && service mysql restart && service cron restart && service php7.0-fpm restart && bash
Build Image
docker build -t magento .
Create Container
docker run -it -d --name magento -h host.name -v /u01/Bilal/test/_data:/var/www/html -p 3020:80 --net mynetwork --ip 172.18.0.51 --privileged magento
It successfully start service in ENTRYPOINT but it randomly shutdown the docker daemon, In docker daemon too no error thrown it just exit from terminal. I searched docker daemon log file by find linux command and this link but I can't find where it is located.
please give suggestions about why it is behave like this?
If I follow any bad practice, please mention?
Related
I'm trying to build a multi platform (linux/amd64,linux/arm64) node image. As far as I understood I can try the corss-compile approach. Building with docker buildx and pushing to the docker registry did not throw any errors. Running the image on the build machine also works fine, but on my raspberry-pi4 (running ubuntu 64bit) following occurs after pulling the image
exec /usr/local/bin/docker-entrypoint.sh: exec format error
My Dockerfile:
FROM --platform=$BUILDPLATFORM node:18-alpine as node
WORKDIR /usr/src/app
RUN echo "console.log('hello world!');" > main.js
EXPOSE 4000
CMD [ "node", "main.js" ]
I builded and pushed my image the following way:
docker buildx build --platform=linux/amd64,linux/arm64 -t buntel/node-multi-arch --push .
I ran my container the following way (no problem on my laptop, but fails on my raspberry-pi):
docker run --rm -it buntel/node-multi-arch
In the docker registry I also see tags for both platforms
https://hub.docker.com/r/buntel/node-multi-arch/tags.
What's going wrong here?
Additional info:
docker buildx ls:
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
loving_tesla * docker-container
loving_tesla0 unix:///var/run/docker.sock running v0.10.4
linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386 default
docker default default
running 20.10.18 linux/amd64, linux/386
docker buildx inspect:
Name: loving_tesla Driver: docker-container
Nodes: Name: loving_tesla0 Endpoint: unix:///var/run/docker.sock
Status: running Buildkit: v0.10.4 Platforms: linux/amd64,
linux/amd64/v2, linux/amd64/v3, linux/386
laptop: docker version
Client: Version: 20.10.18 API version: 1.41 Go
version: go1.19.1 Git commit: b40c2f6b5d Built:
Sat Sep 10 11:31:10 2022 OS/Arch: linux/amd64 Context:
default Experimental: true
Server: Engine: Version: 20.10.18 API version: 1.41
(minimum version 1.12) Go version: go1.19.1 Git commit:
e42327a6d3 Built: Sat Sep 10 11:30:17 2022 OS/Arch:
linux/amd64 Experimental: false containerd: Version:
v1.6.8 GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6.m
runc: Version: 1.1.4 GitCommit: docker-init:
Version: 0.19.0 GitCommit: de40ad0
raspberry-pi docker version:
Client: Docker Engine - Community Version: 20.10.18 API
version: 1.41 Go version: go1.18.6 Git commit:
b40c2f6 Built: Thu Sep 8 23:10:58 2022 OS/Arch:
linux/arm64 Context: default Experimental: true
Server: Docker Engine - Community Engine: Version:
20.10.18 API version: 1.41 (minimum version 1.12) Go version: go1.18.6 Git commit: e42327a Built: Thu Sep 8
23:09:16 2022 OS/Arch: linux/arm64 Experimental:
false containerd: Version: 1.6.8 GitCommit:
9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6 runc: Version:
1.1.4 GitCommit: v1.1.4-0-g5fd4c4d docker-init: Version: 0.19.0 GitCommit: de40ad0
UPDATE:
In my case, I didn't need to emulate anything, because I didn't handle binary builds. So for me, the key was to use --platform=$BUILDPLATFORM on my build stage and --platform=$TARGETPLATFORM on the final stage. This will use the architecture of the machine building the docker image to build my JavaScript/Typescript. And then switch to the target architecture when collecting the build artifacts, which can then be run by those machines.
Example:
FROM node:18-alpine as node
WORKDIR /usr/src/app
RUN echo "console.log('hello world!');" > main.js
FROM --platform=$TARGETPLATFORM node:18-slim
WORKDIR /usr/src/app
COPY --from=node /usr/src/app/main.js .
CMD [ "node", "main.js" ]
EXPOSE 4000
The issue is you're using BUILDPLATFORM, which will always be the same architecture as the host machine. In this case, it will always be x86_64. What you want is the TARGETPLATFORM, which will be implicit anyway. You can see this in an explanation of multi-platform Docker builds.
You can get the Docker info using docker version | grep 'OS/Arch' (this will give the client first, then the server).
What you actually want is to use the node:18-alpine image for the linux/arm64 when building for that platform. Changing it to the following will work:
FROM node:18-alpine as node
WORKDIR /usr/src/app
RUN echo "console.log('hello world!');" > main.js
EXPOSE 4000
CMD [ "node", "main.js" ]
If you still want to build for linux/amd64 and run it on your ARMv8 machine, you would have to install binfmt to register these x86_64 binaries with the correct Qemu emulator. This would be then emulating x86_64 on your ARM machine, which you almost certainly do not want to do.
Both of your images were built for your build platform rather than the target platform with this line:
FROM --platform=$BUILDPLATFORM ...
You don't want --platform=$BUILDPLATFORM on the target stage. This is used on the intermediate stages that either cross compile or output non-platform specific results that you can copy into the target stage.
More details on these variables defined by buildkit is available at: https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
I'd also change your RUN step to a COPY step, which eliminates the need for any emulation on the build server. This means running:
echo "console.log('hello world!');" > main.js
in the same directory with your Dockerfile, to create the main.js file in your build context. Then change the Dockerfile to have:
FROM node:18-alpine as node
WORKDIR /usr/src/app
COPY main.js .
EXPOSE 4000
CMD [ "node", "main.js" ]
With that you can build multi-platform images using your original docker buildx build command.
I'm using following system version/spec for the docker-redis setup using default redis.conf.
Redhat version: 7.6 (Red Hat Enterprise Linux Server)
Redis Version: 5.0.4
Docker Version: 1.13.1, build b2f74b2/1.13.1
When I run following command it's working perfectly fine.
sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
I need to get redis data (which is in /data inside the container) to the host directory (/usr/local/etc/redis/data) (-v $PWD/data:/data). So when I run following command I'm getting the below error.
Note $PWD = /usr/local/etc/redis/
sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf -v $PWD/data:/data --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
Error in docker logs:
journal: chown: changing ownership of '.': Permission denied
level=warning msg="05ce842f052e28566aed0e2eab32281138462cead771033790266ae145fce116 cleanup: failed to unmount secrets: invalid argument"
Also I tried changing the ownership of the data folder in the host to following as well. chown redis:redis data
drwxrwxrwx. 2 redis redis 6 May 3 07:11 data
Can someone help me out on this. Thanks.
First create a volume:
docker volume create redis_data
Check the volume is created (note the Mountpoint):
docker volume inspect redis_data
Then use this volume to start your container:
sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf -v redis_data:/data --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
You can then check the contents of the "Mountpoint" that should be the redis data.
I have a gitlab CI pipeline setup and sometimes I get random failures where the test is on-going but then it shows:
ERROR: Job failed (system failure): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
What could be the reason for this?
This is on Gitlab 11.1.4, gitlab-runner 10.7.4, Docker version 1.13.1.
Ok.
So a docker container cannot be created.
It could be those Reasons:
- the user gitlab-runner (the one who take the pipelines and starts them) is not member of the docker group
- sudo usermod -a -G docker gitlab-runner
- The Daemon is not running. Enable it (so that it start at boot)
systemctl enable docker && systemctl start docker
The problem seemed to be a too old docker daemon. Recent docker versions >= 18.06.0-ce seem to behave well.
When running my docker-compose-development.yaml on my computer, I can't connect to http://localhost:8080.
Also, I can run docker-compose -f docker-compose-development.yaml exec web curl http://localhost:8080 and I got a result. So it seems to not be a code problem.
What I've already done:
Connect directly on container IP with $ docker inspect ...
Try on another Windows 10 laptop (it works)
Change localhost to 127.0.0.1 or 0.0.0.0
Try another port than 8080
This is my $ docker version :
Client:
Version: 17.11.0-ce
API version: 1.34
Go version: go1.8.4
Git commit: 1caf76c
Built: Mon Nov 20 18:30:11 2017
OS/Arch: windows/amd64
Server:
Version: 17.11.0-ce
API version: 1.34 (minimum version 1.12)
Go version: go1.8.5
Git commit: 1caf76c
Built: Mon Nov 20 18:39:28 2017
OS/Arch: linux/amd64
Experimental: true
This is my Dockerfile:
FROM node:9.1-alpine
RUN npm install -g nodemon
WORKDIR /opt/webserver/
COPY . /opt/webserver
RUN npm install
CMD ["npm","run","start"]
EXPOSE 8080
RUN rm -rf /tmp/* /var/tmp/*
This is my docker-compose-development.yaml:
version: "3"
services:
web:
image: registry.gitlab.com/soundtrack/webapp
ports:
- "8080:8080"
links:
- database
volumes:
- ".:/opt/webserver:rw"
database:
image: mongo:3.4.10
ps command from docker-compose:
$ docker-compose -f .\docker-compose-development.yaml ps
Name Command State Ports
--------------------------------------------------------------------------------
webapp_database_1 docker-entrypoint.sh mongod Up 27017/tcp
webapp_web_1 npm run start Up 0.0.0.0:8080->8080/tcp
I ran my container:
docker run -d -it -p 10080:80 --name=container-cool-name <container-id>
And I could see my running app with curl (inside the container)
docker exec -ti container-cool-name bash
#curl localhost:80
Here I read:
If you’re using Docker Toolbox
"docker-machine ip will tell you"
My app was correctly displaying at 192.168.99.100:10080
Try following steps,
1 - List all the running docker containers
docker ps -a
After you run this command you should be able to view all your docker containers that are currently running and you should see a container with the name webapp_web_1 listed there.
2 - Get the IP address where your webserver container is running. To do that run the following command.
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" webapp_web_1
Try accessing the IP which is shown after running above command and access your running container with that IP instead of localhost.
I have answered to a simillar question related to this exact problem on Windows. Please refer it via this link to get a detailed idea on why this issue prevails.
Hope this helps you out.
I've tried to get my setup work with gitlab-ci. I have a simple gitlab-ci.yml file
build_ubuntu:
image: ubuntu:14.04
services:
- rikorose/gcc-cmake:gcc-5
stage: build
script:
- apt-get update
- apt-get install -y python3 build-essential curl
- cmake --version
tags:
- linux
I want to get a ubuntu 14.04 LTS with gcc and cmake (apt-get version is to old) installed. If i use it locally (via docker --link command) everything works, but when the gitlab-ci-runner will process it i get the following waring (which is in my case an error)
Running with gitlab-ci-multi-runner 9.2.0 (adfc387)
on xubuntuci1 (19c6d3ce)
Using Docker executor with image ubuntu:14.04 ...
Starting service rikorose/gcc-cmake:gcc-5 ...
Pulling docker image rikorose/gcc-cmake:gcc-5 ...
Using docker image rikorose/gcc-cmake:gcc-5
ID=sha256:ef2ac00b36e638897a2046c954e89ea953cfd5c257bf60103e32880e88299608
for rikorose/gcc-cmake service...
Waiting for services to be up and running...
*** WARNING: Service runner-19c6d3ce-project-54-concurrent-0-rikorose__gcc-
cmake probably didn't start properly.
Error response from daemon: Cannot link to a non running container: /runner-
19c6d3ce-project-54-concurrent-0-rikorose__gcc-cmake AS /runner-19c6d3ce-
project-54-concurrent-0-rikorose__gcc-cmake-wait-for-service/runner-
19c6d3ce-project-54-concurrent-0-rikorose__gcc-cmake
Does anybody know how i can fix this?
Thanks in advance
Tonka
You must start the gitlab-runner container with
--privileged true
but that is not enough. Any runner containers that are spun up by gitlab after registering need to be privileged too. So you need to mount the gitlab-runner
docker exec -it runner /bin/bash
nano /etc/gitlab-runner/config.toml
and change privileged flag from false into true:
privileged = true
That will solve the problem!
note: you can also mount the config.toml as a volume on the container then you won't have to log into the container to change privileged to true because you can preconfigure the container before running it.
In my case, I had to add
variables:
DOCKER_TLS_CERTDIR: ""