PacktPublishing / Microservices-with-Go

Microservices with Go, published by Packt
MIT License
139 stars 56 forks source link

Problem with Dockerfile #5

Closed luispinto23 closed 1 year ago

luispinto23 commented 1 year ago

Hello @b441berith , I've reported an errata about the Dockerfiles in chapter 8 and I've seen that they've already been added here in the repo and I really thank you for that. Although, with the provided Dockerfile I am still struggling to make the service run. This is my current Dockerfile (as is provided now in the repo)

# Dockerfile inside src/metadata
FROM alpine:latest
COPY main .
COPY configs/. .
EXPOSE 8081
CMD ["/main"]

This compiles without any error, but when I then run the container using the provided command from the book docker run -p 8081:8081 -it metadata I got the following result: image

I've entered the container to check what's inside and the main executable is present as you can see in the following screenshots:

-- File tree: image

-- metadata container: image

Is there anything missing in the Dockerfile or am I doing something else wrong?

Thank you, and I am loving the book.

b441berith commented 1 year ago

Hi Luis,

Thanks for flagging the Dockerfile issue before. As mentioned in Chapter 8, before you run the docker command, you need to build the executable binary (called main) by running GOOS=linux go build -o main cmd/*.go inside each service directory. The result of each execution would be a new file called main, that would be included into a Docker image once you run the docker command next time. I would add that an alternative to this would be to let Docker build our Go code itself, but it my experience such images are much larger and the configuration is slightly more complex.

Hope this helps, Alex

On Fri, Feb 17, 2023 at 2:20 PM Luís Pinto @.***> wrote:

Hello @b441berith https://github.com/b441berith , I've reported an errata about the Dockerfiles in chapter 8 and I've seen that they've already been added here in the repo and I really thank you for that. Although, with the provided Dockerfile I am still struggling to make the service run. This is my current Dockerfile (as is provided now in the repo)

Dockerfile inside src/metadata

FROM alpine:latest COPY main . COPY configs/. . EXPOSE 8081 CMD ["/main"]

This compiles without any error, but when I then run the container using the provided command from the book docker run -p 8081:8081 -it metadata I got the following result: [image: image] https://user-images.githubusercontent.com/4148663/219804160-015dec57-affb-4851-9ca8-fbf36a46cb7b.png

I've entered the container to check what's inside and the main executable is present as you can see in the following screenshots:

-- File tree: [image: image] https://user-images.githubusercontent.com/4148663/219804402-a3c82db5-1f21-44a2-abf6-00719c6c64a2.png

-- metadata container: [image: image] https://user-images.githubusercontent.com/4148663/219804504-107003aa-3264-47a3-9fd1-9ac684f5cd27.png

Is there anything missing in the Dockerfile or am I doing something else wrong?

Thank you, and I am loving the book.

— Reply to this email directly, view it on GitHub https://github.com/PacktPublishing/Microservices-with-Go/issues/5, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE6OOSWBBH6RMYGMIV2DRDWX72TXANCNFSM6AAAAAAU75VCUU . You are receiving this because you were mentioned.Message ID: @.***>

luispinto23 commented 1 year ago

Hey Alex, really appreciate your work and that you've been replying so fast.

I might have worded it bad in the issue description, but I've indeed ran the command to build the code and generate the executable. I've provided the screenshots to highlight that the main executable is indeed there, but still the Docker run command yields that there's no such file or directory.

I will try to follow with the reading of the book disregarding this, but I am afraid that it will get in the way of the next chapters since I'll not really be able to run the services from the containers.

b441berith commented 1 year ago

I see, sorry for missing your comments. I will check later today once I’m at home, could be related to the leading / character in EXEC command.

On Fri, Feb 17, 2023 at 2:54 PM Luís Pinto @.***> wrote:

Hey Alex, really appreciate your work and that you've been replying so fast.

I might have worded it bad in the issue description, but I've indeed ran the command to build the code and generate the executable. I've provided the screenshots to highlight that the main executable is indeed there, but still the Docker run command yields that there's no such file or directory.

I will try to follow with the reading of the book disregarding this, but I am afraid that it will get in the way of the next chapters since I'll not really be able to run the services from the containers.

— Reply to this email directly, view it on GitHub https://github.com/PacktPublishing/Microservices-with-Go/issues/5#issuecomment-1435370094, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE6OOQ6K77UNP7F3WZLDVDWX76RRANCNFSM6AAAAAAU75VCUU . You are receiving this because you were mentioned.Message ID: @.***>

Maran9 commented 1 year ago

Hi @b441berith were you able to get a chance to review the command?

b441berith commented 1 year ago

I checked the local image and it matches the one on Github. Screenshot of the actual image from Docker registry:

image

It ran fine for me:

$ docker run -p 8081:8081 -it metadata 2023/02/22 00:05:47 Starting the metadata service on port 8081

ls command also shows similar output:

image

I'll think what else could have caused inability to locate the main file.

luispinto23 commented 1 year ago

@b441berith I got my PC back today and I was trying to put everything working again and it just worked this time around (I am in a different distro though - currently using Ubuntu through WSL, and was previously on Fedora). In respect to code I am using the same file that I was using previously so I am not sure what made it work this time.

Again, thanks for your help and please let me know if there's a better way to approach you if anything else comes up with the book examples instead of opening an issue in this repo.

mkvy commented 1 year ago

Same problem in Ubuntu

jasonsalas commented 1 year ago

I found a workaround to this issue by installing the bash shell in the Alpine Linux container:

src/metadata/Dockerfile

FROM alpine:latest RUN apk update && apk upgrade RUN apk add bash COPY main . EXPOSE 8081 CMD ["./main"]