- Login to your registry (e.g. hub.docker.com by default)
docker login
username: xxxx
password: xxxx
- Prepare Env Variables and build docker image
export USER_GIT_NAME="aleon1220"; export VERSION="v5"; export APP_ENV="environment_name"
# Use another Branch if required. Command below gets the latest commit ID.
export COMMIT_ID=$( git rev-parse origin/master )
- Build docker image
docker build \
--build-arg VERSION=$VERSION \
--build-arg COMMIT_ID=${COMMIT_ID} \
--build-arg APP_ENV=${APP_ENV} \
--tag ${USER_GIT_NAME}/hostname:${VERSION} .
- Push the image
docker push -t {USER_GIT_NAME}/hostname:$VERSION
- Run the image:
docker run --rm --name hostname -p 8080:80 -d $USER_GIT_NAME/hostname:$VERSION
curl http://localhost:8080
docker stop hostname
docker rmi $USER_GIT_NAME/hostname:v1
docker rmi nginx:latest