Part 7: Run from the Docker Hub images
Continued from previous blog
Previous blog tells about build, push image form local to an docker-hub.
In this we are going to see how to run form the docker image.
Steps :
$ mkdir pull-from-image
$ cd pull-from-image
Add docker-compose.yml and Docker file into directory
docker-compose.yml
version: "3"
services:
app:
build: .
command: "bundle exec puma -p 3000 -e development -b unix:///var/run/puma.sock
-C config/puma.rb"
ports:
- "3000:3000"
volumes:
- ./app/log:/app/log
environment:
- DB_USER_NAME=postgres
- DB_HOST=localhost
- DATABASE_NAME=db_name
- DB_PASSWORD=password
bundle:
# 'image' will vary depending on your docker-compose
# project name. You may need to run `docker-compose build web`
# before this works.
image: ubuntu
Note: update the environment: with local database details
Docker
FROM pvin/docker_test:1.5
ENV APP_HOME /myappWORKDIR $APP_HOME
Note:
pvin/docker_test:1.5 => docker_id/remo_name:(version/tag)/myapp => While creating the image of the app, name /myapp is used for keeping the all required file. example: RUN mkdir /myapp
Once all set run below listed comments
$ sudo docker-compose build #to build
$ sudo docker-compose run app bundle install #to install gems
$ sudo docker-compose up #to run the app
hit the url localhost:3000 or 172.17.0.1:3000 which ever the IP address given in database.yml -> host : 172.17.0.1
Done ! you can see the landing page
One More important thing is use dotenv gem for setting up the user name and password from the ENV file. Because once image is made can’t be edit, so if we keep it as ENV variable and value can be set at .env file based on db.