Saturday, November 16, 2019

Images, Containers and Docker Registry

This tutorial shows how to create images and containers and push to hub.docker.com registry. GitHub repo is at https://github.com/nikola-bodrozic/Docker-ReactJS

Simple Build on Linux

Apache web server no Dockerfile, $(pwd) prints path to current folder

docker run -d --name apa -e TZ=UTC -p 8080:80 -v $(pwd)/html/:/var/www/html/ ubuntu/apache2

Development Build

docker build -t reactapp:1.0 .
docker run -p 3000:3000 \ 
       --env REACT_APP_BASE_URL=localhost \ 
       --name react-app reactapp:1.0
docker logs -f YOUR_CONTAINER_SHA

Prod build & push to registry

Create empty private image repo at DOCKER_HUB_USERNAME/REPO_NAME

The repo should be visible in browser at https://hub.docker.com/repository/docker/DOCKER_HUB_USERNAME/REPO_NAME

For production you need to set env variable in Dockerfile-prod not in docker run. Here's how
RUN REACT_APP_BASE_URL=example.com yarn build

build, run and push to registry

docker run -d \
           -p 80:80 \
           --name react-app-prod DOCKER_HUB_USERNAME/REPO_NAME:1.0

docker build -t DOCKER_HUB_USERNAME/REPO_NAME:1.0 \
             -f Dockerfile-prod .

docker login

docker push DOCKER_HUB_USERNAME/REPO_NAME:1.0
DOCKER_HUB_USERNAME/REPO_NAME:1.0

No comments:

Post a Comment