Hey everyone! I'm trying to learn Docker on my Ubuntu laptop and made a simple Dockerfile to ping 8.8.8.8. When I run my container after a fresh reboot, it pings successfully the first time, but on subsequent attempts, I get 100% packet loss. Here's my Dockerfile:
```
FROM alpine
RUN apk add python3
CMD ["8.8.8.8"]
ENTRYPOINT ["ping", "-c", "5"]
```
After building the image with `docker build . -t myweb:3`, it works great at first. However, every time I try to run it again, I face packet loss. I've even checked the network settings and created a custom network, but I'm still stuck.
I noticed that if I ping google.com instead, it tries to use IPv6 and I run into the same issue. I'd appreciate any advice on what might be going wrong. Thanks!
3 Answers
Have you tried running the ping command natively in an Alpine container first? Pinging public IPs can sometimes be tricky since many sites like Google block ICMP requests to avoid attacks. It might not even be a container issue, but rather how Google sees your requests. A tool like curl would be better for checking URL access instead of pinging directly.
Consider swapping your CMD and ENTRYPOINT around. The ENTRYPOINT is for setting up the executable, while CMD should handle parameters you want to pass. And why add Python if all you're needing is to ping? Just a curious thought!
Good point! I’m following a course on Udemy, and I guess that was just a step in their setup.
Try running this command directly in your terminal:
```
docker run -it --rm alpine ping google.com
docker run -it --rm alpine ping google.com
```
See how that behaves for you.
I’ll give that a shot! Just to clarify, should I put that in the CMD section for my Dockerfile?
No, run those directly in your terminal. Let me know what happens!
I can ping google.com fine from my terminal, but I see what you mean about the ICMP requests.