I am trying to setup Pumba on my docker swarm setup. I tried using the docker service create, docker stack deploy and a simple docker run command with following parameters:
docker run -d -v /var/run/docker.sock:/var/run/docker.sock gaiaadm/pumba:master Pumba kill --signal SIGTERM
docker service create --constraint 'node.role == manager' --mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock gaiaadm/pumba:master --with-registry-auth
docker-compose.yaml is:
version: "3.4"
services:
pumba:
image: gaiaadm/pumba:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
replicas: 3
command: ["pumba", "kill","re2:^customer-api*","--signal", "SIGTERM"]
and created the above compose file for stack deploy.
But in all the cases the pumba container just kills the mentioned container as customer-api* in compose file above and exits and restarts due to swarm maintaining state feature
I need the container to keep running.
I am new to docker and Pumba any help or direction will be really appreciated.
Thanks in advance.
I am able to solve the problem using the following service create command:
docker service create --name PUMBA --mode=global --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock gaiaadm/pumba:master pumba --random --interval 10s kill re2:"^customer-api*" --signal SIGTERM
I deployed it in global mode and changed Pumba command, after doing this Pumba doesn't kill itself and container keeps on running.
Related
I'm starting with Docker and Laravel. I've cloned the Laradock images from GitHub. The services are running fine with this command: (from into the path of Laradock)
#docker-compose up -d apache2 gitlab
The problem is in the startop of the OS. The containers doesn't running.
I've read from the ofical documentation of Docker and there is the command:
#docker run -dit --restart unless-stopped laravel_apache2
#docker run -dit --restart unless-stopped laravel_gitlab
I'm not sure why when I've restarted the machine the services are running(docker ps) but I haven't access to the server by apache2 and Gitlab.
If it is execute again the first commmand from the path:
#docker-compose up -d apache2 gitlab
It's working fine again.
I'm sure that the problem is between docker and docker-compose I don't know how to put in the startup the containers running by docker-compose command.
Should be I have build a container and move or config by different way :(
Please Could you help me to put in the startup a containers running by docker-compose?
Thanks!
The best way to make this behavior permanent, is to modify the docker-compose.yml, by adding the following line to each service that you need the OS to restart upon startup: restart: unless-stopped
Once you saved the modified docker-compose.yml file, you'll need to restart your services, example:
docker-compose down
docker-compose up -d apache2 gitlab
I am able to run a docker container using following docker command:
docker run -it ubuntu /bin/bash
Now I am trying to do it by using docker-compose:
version: "3"
services:
ubuntu:
container_name: ubuntu
image: ubuntu
restart: on-failure
command: "/bin/bash"
Now when I do :
docker-compose up -d
Can see docker container starting and exiting immediately.
I tried looking at the logs :
docker logs b8 //b8 is container id
But there are no error logs.
How do I keep ubuntu container running in background using docker.
( I am using docker on windows , linux version)
This is normal.
You are starting an ubuntu container with bash as the command (thus the root process). The thing is to keep bash alive you need to attach it with a terminal. This is why when you want to get a bash in a container, you're using -ti with your command :
docker container exec -ti [my_container_id] bash
So if you want to keep your ubuntu container alive and don't want to attach it to a terminal, you'll have to use a process that will stay alive for as long as you want.
Below is an example with sleep infinity as your main process
version: "3"
services:
ubuntu:
container_name: ubuntu
image: ubuntu
restart: on-failure
command: ["sleep","infinity"]
With this example, you container will stay running indefinitely.
I run my container by five Docker commands as follows:
docker run --privileged -d -v /root/docker/data:/var/lib/mysql -p 8888:80 testimg:2 init
docker ps ---> to get container ID
docker exec -it container_id bash
docker exec container_id systemctl start mariadb
docker exec container_id systemctl start httpd
I was trying to do these steps by docker-compose but failed.
Can somebody make a docker-compose.yml or Dockerfile to get same result for me?
You're not going to be be able to do this with just a docker-compose.yml, because a compose file doesn't have any mechanism similar to docker exec. Additionally, running systemd (or really any process manager) inside a container is an anti-pattern. It can complicate the management and scaling of your containers, and in most cases doesn't provide you with any benefits.
Why don't you just have two images:
One that starts mariadb
One that starts Apache httpd
That might look something like:
version: "3"
services:
web:
image: httpd
ports:
- "8888:80"
db:
image: mariadb
volumes:
- "/root/docker/data:/var/lib/mysql"
You would probably need a custom image for the web server containing whatever application you're running, but you can definitely use the official mariadb image for your database.
I'd like docker-compose to use an already running container for imageA and not create it a second time when calling docker-compose up -d. The original container was run using docker run.
Steps:
I started a container with docker run, eg.
docker run --name imageA -d -p 5000:5000 imageA
I then call docker-compose up -d with a docker-compose.yml file that includes a service with the same name and image as the first container.
version: "3"
services:
imageA:
image: imageA
ports:
- "5000:5000"
imageB:
image: imageB
ports:
- "5001:5001"
What happens:
docker-compose tries to create imageA and fails when it tries to bind port 5000 since container imageA has it bound already.
Question: How can docker-compose "adopt" or "include" the first container without trying to create it a again?
I don't believe this is currently possible. If you compare the outputs of docker ps and docker-compose ps, you should notice that docker-compose ps does not show the imageA running, if it was started with docker run.
Docker-compose is only interested in the services that are defined in the docker-compose files, and it does not seem to use only the container names for that, but labels too, and you cannot add labels to running containers currently.
Other than that, the container started with docker run will also not be (at least by default) in the same internal network as those that are started with docker-compose.
So your best option would be either:
a) Removing the already running container from the compose-file.
b) Calling docker-compose up -d imageB to run only the individual service, so that the compose updates only that or
c) just stopping the already running container and starting it again with compose.
Docker containers should anyway be created in a way that it is easy and acceptable to just restart them when needed.
Adding --no-recreate flag will prevent recreation of the container, if it already exists.
Example:
docker-compose -f docker-compose-example.yaml up -d --no-recreate
I have a dockerfile to install httpd. When i run this dockerfile using the command
docker run -dit /bin/bash,
the container is started and it is running in the background. when i perform docker ps i could see the container running.
I have created a docker-compose.yml file as below,
version: '2'
services:
web:
build:
context: ./web
dockerfile: Dockerfile-apache
image: web:1.0
container_name: web
ports:
- "80:80"
command: service httpd start
i have build this compose file using the
docker-compose build.
Once after that i started the containers using
docker-compose up -d.
The containers are getting exited. i am not sure how to make the containers run at background.
Also i want to make the services running inside the container. For example i need to run the command like service httpd start inside the container and how to do it ?
This is because a Docker container only lives as long as its command runs.
Your command service httpd start will start httpd in the background and then exit. This will terminate httpd and the container.
You will have to run the httpd process directly and in the foreground, see the official image's start script:
httpd -DFOREGROUND
You can't run docker with -dit options together. -d means to run it in background mode and -ti means an interaction with terminal. So, have to run with -d OR with -ti and not both