Dockerize a Photosite rails application - SeshuVarma/websys GitHub Wiki
Dockerize a photosite rails application
- Docker allows you to package up an application or service with all of its dependencies into a standardized unit which is called a Docker image.
- The Docker image contains everything the application needs to run is included Eg. the code, runtime, system libraries, and anything else you would install on a server to make it run if you weren’t using Docker.
- Once the Docker is installed and running successfully in your machine, Create a docker file.
- A Dockerfile is a way to describe a docker image that contains all the commands that you would need to install the programs and libraries.
- Dockerfile starts with a basic image, in this case, we're using ruby:2.7.0-alpine and write the code to install all dependencies of the application to run successfully.
i. Build a Docker image
After creating Dockerfile build a Docker image for photosite rail application using the command docker build -t photosite-railapp.
ii. Run a Docker image
Docker run starts a new container and runs a program inside.docker run -it -p 3000:3000 photosite-railapp:latest
iii. Testing It Out
Head over to http://localhost:3000 It should be greeted with the typical Rails introduction page in our case it should list out all the users in the database.
iv. Push Docker image to Docker Hub
-
Log in on https://hub.docker.com/
-
Create Repository.
-
Choose a name (e.g. rojabalakrishnan) and a description for your repository and click Create.
-
Log into the Docker Hub from the command line using command docker login
-
Check the image ID using command docker images and and tag your image using command docker tag photosite-railapp:latest rojabalakrishnan/photosite-railapp
-
Push your image to the repository you created docker push rojabalakrishnan/photosite-railapp
-
After successfully pushed to Docker Hub, the image will be publicly available under your repository.