Skip to content

BhairaviSanskriti/OrderFood-Running-CLI-Application-Inside-A-Container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OrderFood-Running-CLI-Application-Inside-A-Container

How to containerize your CLI application and run it

I have make a cli application using Go and I want to containerize it.

Here are the steps that I followed:

  1. Base image of the container → golang:1.18.6-alpine3.16 . It’s more apt because it’s size is small in comparison to other golang images, and also because we want to run a GO cli application.

  2. Then, I created a container using this base image and named it food-app. Entered into it. Created a directory /order-food and wrote my code within this directory. My code constitutes files naming - main.go, bill.go, go.mod, greet.go, menu.go, modify.go, order.go .

  3. I've added the code files. You can also refer to this:https://github.com/BhairaviSanskriti/Order-Food repo to gain more insight on what this application is about.

  4. After writing all the neccessary files into this directory we will exit out of this container.

  5. Make an image of this container by executing docker commit food-app bhairavisanskriti/cli-app-image command. This command will create an image of the name bhairavisanskriti/cli-app-image . As we have not specified the tag, so default tag will be assigned to it. image

  6. Login to Docker by executing docker login command.

  7. Push this image to the docker hub by running docker push bhairavisanskriti/cli-app-image:latest command. image

  8. Now, create a Dockerfile, and make changes to it:

    1. Image name → bhairavisanskriti/cli-app-image:latest
    2. Working directory → We want to be inside /order-food directory once we enter the container, because that’s where our application code lies.
    3. Run command go run . to execute the code in the current working directory of your container once it gets created. image
  9. Save Dockerfile and build the image named order-food-image out of this file. → docker build -t order-food-image . image

  10. Create and run a container out of this image by executing : docker run -it --name order-food-container order-food-image image

  11. Start using the CLI application.

  12. The container, if it gets stopped then you can enter into it by executing docker exec -it order-food-container ash command. Then run the cli app by running go run .command. image

Your Go CLI application is containerized and it's running.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published