
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 or make a comment on whatever help me improve. โค๏ธ
Blog Menu
- ๐ผ hire my consultancy
- โน๏ธ about me
- ๐ฐ rss
- โ๏ธ Spend a day with me
- tech and life
- ๐ blogs
- 2025-05-16
Spending 5 Minutes to Make a Point ๐
This blog post is an exercise. I want to make a point, and for that, I will need to do some research and tell a story. Telling a story Henry Ford was ...
- 2025-05-14
Non technical founders, Visionary Builders Community ๐ฏโโ๏ธ
This is my third community. I’m starting to understand how it works. People with similar interests or challenges tend to have similar insights a...
- 2025-05-13
2nd CTO Event Is Soon ๐ช
What’s about it? I host Armenian CTO Community. We have already 109 members there. First event hosted 21 members! I am doing this for over 9 mo...
- 2025-05-12
Reducing the Friction to Post ๐ช๏ธ
Eliminating the reasons I don’t blog, one by one. Opening the editor is a friction, writing is a friction, pushing is a friction, but I can make...
- 2025-05-07
Consistency and Time โฒ๏ธ
Do I have time to blog? Every time I wrote I will blog every day, I’ve reflected on this commitment in several posts: In I Need to Revisit My Bl...
- 2024-12-29
Then the Journey Is Not About Winning ๐๏ธ
Winning is the target, but the journey is never about winning. You cannot be sure the path is correct. Even with guidance, there is a chance it’...
- 2024-12-28
Free Consultancy ๐๐ป
Nobody buys it. When I provide it everyone is happy. Why? Maybe people don’t understand the offer, which is completely understandable. What I of...
- 2024-12-28
The Algorithm of the Dressings ๐ฅฌโ๐ฅโโ๏ธ๐ฐ๐ฅ
Martun said he read many books about healthy food and didn’t become healthy. I agree, that reading and doing is very different. But I think that...
- 2024-12-25
Powered.community Meetup ๐ค๐ป
Well, it happened. The food was sushi, and people came with friends, some just checking in. I was so glad to see so many people I know and don’t...
- 2024-12-23
5 Books to Read Before 2025 to Transform Your Life ๐๏ธ
People are not computers, though we share traits such as short and long-term memory or processing power. You cannot install a “software” o...
- See all...
- ๐ links