Ruben's Blog | ีีธึีขีฅีถีซ ิฒีฌีธีฃีจ
๐ ..Tips on troubleshooting Docker Image build, Compose and Swarm issues ๐ณ๐ณ๐ณ
Docker has revolutionized the way we develop, deploy, and manage applications, allowing us to create lightweight and isolated containers that encapsulate our applications’ dependencies and runtime environments. However, like any technology, Docker can present its fair share of challenges. In this blog post, we will delve into the world of troubleshooting Docker image builds, Docker Compose, and Docker Swarm failures, and explore some troubleshooting techniques I use that may help you save time.
Dockerfile
Troubleshooting docker image “build failed”
Let’s say we have a Dockerfile which doesn’t build. Let’s say it looks like this.
FROM ubuntu
RUN echo "build started"
RUN apt install -y curl
RUN echo "build finished"
The output will look something like this.
Let’s say we don’t understand why it’s failing, though in this case it’s written clearly.
we can do following, comment out all the lines in the dockerfile up to the point of failing line.
FROM ubuntu
RUN echo "build started"
# RUN apt install -y curl
# RUN echo "build finished"
build it docker build -t test-image .
Run image and shell into it docker run -it test-image bash
.
Explore the image from the inside and try to fix the issues.
and now if we do apt install -y curl
it’s finally installed.
So we put the fix in the dockerfile and everything builds normally.
Compose
Troubleshooting docker compose doesn’t start properly
If you don’t understand why your servers are not starting and you are at a dead end, you can always comment it out. Start by commenting one by one and running after each change to troubleshoot
- networks
- ports
- volumes
- Containers that depend on other containers
Swarm with compose
Common reasons why your docker-compose may work on it’s own and not work with the swarm
Networking issue
- Note that docker swarm cannot allocate a static IP to a machine, the main reason is that if there is more than 1 server it will not know to which server to allocate it.
- You can try commenting on all network parameters in compose file.
Volume issue
- If you use virtual volumes in most cases you will not get a problem, otherwise, docker swarm will not start, the issue is that in the secondary nodes volume will not be found.
There are 2 solutions to this problem
- Use virtual volumes
- Create directories and provide absolute paths to the volume.
volumes: - /absolute-path-to-volume:/app/data
Exposed Ports issue
- Try commenting out exported ports in docker compose.
- There might be some network misconfiguration
- Another possibility is another server docker or a non-docker is running. In this case, you will need to disable the server or change the exposed ports.
ENV variables
- You cannot use
env_file:
when running docker swarm, the reason is that on the secondary nodes, you may not have the file, and thus docker cannot read it, useenvironment:
instead- I actually wrote a script in Makefile that created a temporary docker compose infused in env variables from
.env
file. It was junky๐๏ธ but it worked.
- I actually wrote a script in Makefile that created a temporary docker compose infused in env variables from
Troubleshooting docker swarm amd docker compose
If you run docker swarm with docker compose and when you do docker service ls
you see that your services may not start. In that cases, you can investigate the service manually.
docker service ps --no-trunc DOCKER_SERVICE_CONTAINER_ID
This command helped me in numerous cases๐๏ธ when I didn’t understand what is wrong with the swarm!
Docker will tell you about the issue. If it’s a network issue try
docker network list
And after you can continue investigating with
docker network inspect DOCKER_NETWORK_ID
Finally ๐ฌ
If you don’t understand the issue, comment something out and run it.
Please give me feedback, comment on whatever you think about my blog post, and help me improve. โค๏ธ
Blog Menu
- ๐ผ hire my consultancy
- โน๏ธ about me
- ๐ฐ rss
- ๐ธ a young blog
- ๐ blog
- 2024-11-15
What Would You Do if It Wasn't for Money? ๐ฑ
What is money? For some it’s freedom. Freedom of choice. For me it’s an equivalent of “ability”. It’s like the magic wan...
- 2024-11-12
First, Rewrite๐
I start to see patterns. I start to see how people work. Not sure how deep I see. I don’t want to exploit people. I don’t want to MAKE peo...
- 2024-11-11
It's Not About Sales ๐๐ป
For me it’s always about how can I help people, if I can’t or if my help is insufficient I would not push. I will push to know the reason ...
- 2024-11-09
Push Push Push Breathe ๐ฌ๏ธ
Am I pushing enough? Am I breathing enough? I do :) There is never enough, there is always enough. Having multiple heats it’s hard to find a bal...
- 2024-11-08
Am I Productive? ๐งจ
Do you feel I’m productive? Are you productive? Is productive about fast results? Is productive about the process? I’m not sure anymore, b...
- 2024-11-07
One Week Later โ๏ธ
Last week was awful, I didn’t have time to breathe. This week is not much better. But we have progress. I have about 3k impressions in 2 days on...
- 2024-10-28
Engineering Solution to Every Problem โ๏ธ
As an engineer, I strive to find engineering solutions to every problem surrounding me, engineering doesn’t mean technical in this case. There a...
- 2024-10-27
I'm Going to Invest in Podcasting More ๐ค
Podcasting is discovery It’s listening to so many familiar and different ideas and being able to ask questions, where people can answer you live...
- 2024-10-26
Scooping Motivation ๐ฆ๐ฉ
For me, motivation is being on the edge. I need to feel that what I do is important to do, at that exact moment. (Probably because of my ADHD) There i...
- 2024-10-24
Reflection on My Journey ๐ญ
You can recover your journey from the history of my blog posts if you have been following, though you also probably know that I don’t need peopl...
- See all...
- ๐ links