Skip to content

Instantly share code, notes, and snippets.

@luszczynski
Last active January 3, 2020 02:38
Show Gist options
  • Save luszczynski/37e445617175bc48641fb44cebfd690a to your computer and use it in GitHub Desktop.
Save luszczynski/37e445617175bc48641fb44cebfd690a to your computer and use it in GitHub Desktop.
Docker push to Openshift (from external machine)

Docker push to Openshift (from external machine)

Export some vars:

MY_USER=admin
MY_PASS=redhat@123
OCP_MASTER_URL=https://ocp-master.example.com:8443

If you are cluster-admin,

REGISTRY_HOST=$(oc get route -n default | grep docker-registry | awk '{print $2}')

If not, just find your registry host and set the registry var:

REGISTRY_HOST=docker-registry-default.apps.example.com

Login to the cluster

oc login $OCP_MASTER_URL -u $MY_USER -p $MY_PASS

Create a project:

oc new-project mytest
PROJECT=mytest

Get your token

MY_TOKEN=$(oc whoami -t)

Log in to the registry

docker login $REGISTRY_HOST -u $MY_USER -p $MY_TOKEN

If you receive the following error:

Error response from daemon: Get https://docker-registry-default.apps.example.com/v1/users/: x509: certificate signed by unknown authority

Just add your registry host in your /etc/docker/daemon.json:

{ "insecure-registries": ["172.30.0.0/16", "docker-registry-default.apps.example.com"] }

or using /etc/sysconfig/docker:

OPTIONS='--insecure-registry=172.30.0.0/16 --insecure-registry=docker-registry-default.apps.example.com --selinux-enabled --log-opt max-size=1M --log-opt max-file=3'

Restart your docker

systemctl restart docker

And try again to login:

docker login $REGISTRY_HOST -u $MY_USER -p $MY_TOKEN

Now tag your image and push to the server

MY_IMAGE=busybox
docker pull $MY_IMAGE
docker tag $MY_IMAGE $REGISTRY_HOST/$PROJECT/$MY_IMAGE
docker push $REGISTRY_HOST/$PROJECT/$MY_IMAGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment