github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/docs/sources/docker-hub-enterprise/quick-start.md (about) 1 page_title: Docker Hub Enterprise: Quick-start: Basic Workflow 2 page_description: Brief tutorial on the basics of Docker Hub Enterprise user workflow 3 page_keywords: docker, documentation, about, technology, understanding, enterprise, hub, registry, image, repository 4 5 6 # Docker Hub Enterprise Quick Start: Basic User Workflow 7 8 ## Overview 9 10 This Quick Start Guide will give you a hands-on look at the basics of using 11 Docker Hub Enterprise (DHE), Docker’s on-premise image storage application. 12 This guide will walk you through using DHE to complete a typical, and critical, 13 part of building a development pipeline: setting up a Jenkins instance. Once you 14 complete the task, you should have a good idea of how DHE works and how it might 15 be useful to you. 16 17 Specifically, this guide demonstrates the process of retrieving the 18 [official Docker image for Jenkins](https://registry.hub.docker.com/_/jenkins/), 19 customizing it to suit your needs, and then hosting it on your private instance 20 of DHE located inside your enterprise’s firewalled environment. Your developers 21 will then be able to retrieve the custom Jenkins image in order to use it to 22 build CI/CD infrastructure for their projects, no matter the platform they’re 23 working from, be it a laptop, a VM, or a cloud provider. 24 25 The guide will walk you through the following steps: 26 27 1. Pulling the official Jenkins image from the public Docker Hub 28 2. Customizing the Jenkins image to suit your needs 29 3. Pushing the customized image to DHE 30 4. Pulling the customized image from DHE 31 4. Launching a container from the custom image 32 5. Using the new Jenkins container 33 34 You should be able to complete this guide in about thirty minutes. 35 36 > **Note:** This guide assumes you have installed a working instance of DHE 37 > reachable at dhe.yourdomain.com. If you need help installing and configuring 38 > DHE, please consult the 39 [installation instructions](./install.md). 40 41 42 ## Pulling the official Jenkins image 43 44 > **Note:** This guide assumes you are familiar with basic Docker concepts such 45 > as images, containers, and registries. If you need to learn more about Docker 46 > fundamentals, please consult the 47 > [Docker user guide](http://docs.docker.com/userguide/). 48 49 First, you will retrieve a copy of the official Jenkins image from the Docker Hub. From the CLI of a machine running the Docker Engine on your network, use 50 the 51 [`docker pull`](https://docs.docker.com/reference/commandline/cli/#pull) 52 command to pull the public Jenkins image. 53 54 $ docker pull jenkins 55 56 > **Note:** This guide assumes you can run Docker commands from a machine where 57 > you are a member of the `docker` group, or have root privileges. Otherwise, you may 58 > need to add `sudo` to the example commands below. 59 60 Docker will start the process of pulling the image from the Hub. Once it has completed, the Jenkins image should be visible in the output of a [`docker images`](https://docs.docker.com/reference/commandline/cli/#images) command: 61 62 $ docker images 63 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 64 jenkins latest 1a7cc22b0ee9 6 days ago 662 MB 65 66 > **Note:** Because the `pull` command did not specify any tags, it will pull 67 > the latest version of the public Jenkins image. If your enterprise environment 68 > requires you to use a specific version, add the tag for the version you need 69 > (e.g., `jenkins:1.565`). 70 71 ## Customizing the Jenkins image 72 73 Now that you have a local copy of the Jenkins image, you’ll customize it so that 74 the containers it builds will integrate with your infrastructure. To do this, 75 you’ll create a custom Docker image that adds a Jenkins plugin that provides 76 fine grained user management. You’ll also configure Jenkins to be more secure by 77 disabling HTTP access and forcing it to use HTTPS. 78 You’ll do this by using a `Dockerfile` and the `docker build` command. 79 80 > **Note:** These are obviously just a couple of examples of the many ways you 81 > can modify and configure Jenkins. Feel free to add or substitute whatever 82 > customization is necessary to run Jenkins in your environment. 83 84 ### Creating a `build` context 85 86 In order to add the new plugin and configure HTTPS access to the custom Jenkins 87 image, you need to: 88 89 1. Create text file that defines the new plugin 90 2. Create copies of the private key and certificate 91 92 All of the above files need to be in the same directory as the Dockerfile you 93 will create in the next step. 94 95 1. Create a build directory called `build`, and change to that new directory: 96 97 $ mkdir build && cd build 98 99 In this directory, create a new file called `plugins` and add the following 100 line: 101 102 role-strategy:2.2.0 103 104 (The plugin version used above was the latest version at the time of writing.) 105 106 2. You will also need to make copies of the server’s private key and certificate. Give the copies the following names — `https.key` and `https.pem`. 107 108 > **Note:** Because creating new keys varies widely by platform and 109 > implementation, this guide won’t cover key generation. We assume you have 110 > access to existing keys. If you don’t have access, or can’t generate keys 111 > yourself, feel free to skip the steps involving them and HTTPS config. The 112 > guide will still walk you through building a custom Jenkins image and pushing 113 > and pulling that image using DHE. 114 115 ### Creating a Dockerfile 116 117 In the same directory as the `plugins` file and the private key and certificate, 118 create a new [`Dockerfile`](https://docs.docker.com/reference/builder/) with the 119 following contents: 120 121 FROM jenkins 122 123 #New plugins must be placed in the plugins file 124 COPY plugins /usr/share/jenkins/plugins 125 126 #The plugins.sh script will install new plugins 127 RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins 128 129 #Copy private key and cert to image 130 COPY https.pem /var/lib/jenkins/cert 131 COPY https.key /var/lib/jenkins/pk 132 133 #Configure HTTP off and HTTPS on, using port 1973 134 ENV JENKINS_OPTS --httpPort=-1 --httpsPort=1973 --httpsCertificate=/var/lib/jenkins/cert --httpsPrivateKey=/var/lib/jenkins/pk 135 136 The first `COPY` instruction in the above will copy the `plugin` file created 137 earlier into the `/usr/share/jenkins` directory within the custom image you are 138 defining with the `Dockerfile`. 139 140 The `RUN` instruction will execute the `/usr/local/bin/plugins.sh` script with 141 the newly copied `plugins` file, which will install the listed plugin. 142 143 The next two `COPY` instructions copy the server’s private key and certificate 144 into the required directories within the new image. 145 146 The `ENV` instruction creates an environment variable called `JENKINS_OPT` in 147 the image you are about to create. This environment variable will be present in 148 any containers launched form the image and contains the required settings to 149 tell Jenkins to disable HTTP and operate over HTTPS. 150 151 > **Note:** You can specify any valid port number as part of the `JENKINS_OPT` 152 > environment variable declared above. The value `1973` used in the example is 153 > arbitrary. 154 155 The `Dockerfile`, the `plugins` file, as well as the private key and 156 certificate, must all be in the same directory because the `docker build` 157 command uses the directory that contains the `Dockerfile` as its “build 158 context”. Only files contained within that “build context” will be included in 159 the image being built. 160 161 ### Building your custom image 162 163 Now that the `Dockerfile`, the `plugins` file, and the files required for HTTPS 164 operation are created in your current working directory, you can build your 165 custom image using the 166 [`docker build` command](https://docs.docker.com/reference/commandline/cli/#build): 167 168 docker build -t dhe.yourdomain.com/ci-infrastructure/jnkns-img . 169 170 > **Note:** Don’t miss the period (`.`) at the end of the command above. This 171 > tells the `docker build` command to use the current working directory as the 172 > "build context". 173 174 This command will build a new Docker image called `jnkns-img` which is based on 175 the public Jenkins image you pulled earlier, but contains all of your 176 customization. 177 178 Please note the use of the `-t` flag in the `docker build` command above. The 179 `-t` flag lets you tag an image so it can be pushed to a custom repository. In 180 the example above, the new image is tagged so it can be pushed to the 181 `ci-infrastructure` Repository within the `dhe.yourdomain.com` registry (your 182 local DHE instance). This will be important when you need to `push` the 183 customized image to DHE later. 184 185 A `docker images` command will now show the custom image alongside the Jenkins 186 image pulled earlier: 187 188 $ sudo docker images 189 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 190 dhe.yourdomain.com/ci-infrastructure/jnkns-img latest fc0ab3008d40 2 minutes ago 674.5 MB 191 jenkins latest 1a7cc22b0ee9 6 days ago 662 MB 192 193 ## Pushing to Docker Hub Enterprise 194 195 Now that you’ve create the custom image, it can be pushed to DHE using the 196 [`docker push`command](https://docs.docker.com/reference/commandline/cli/#push): 197 198 $ docker push dhe.yourdomain.com/ci-infrastructure/jnkns-img 199 511136ea3c5a: Image successfully pushed 200 848d84b4b2ab: Image successfully pushed 201 71d9d77ae89e: Image already exists 202 <truncated ouput...> 203 492ed3875e3e: Image successfully pushed 204 fc0ab3008d40: Image successfully pushed 205 206 You can view the traffic throughput while the custom image is being pushed from 207 the `System Health` tab in DHE: 208 209 ![DHE console push throughput](../assets/console-push.png) 210 211 Once the image is successfully pushed, it can be downloaded, or pulled, by any 212 Docker host that has access to DHE. 213 214 ## Pulling from Docker Hub Enterprise 215 To pull the `jnkns-img` image from DHE, run the 216 [`docker pull`](https://docs.docker.com/reference/commandline/cli/#pull) 217 command from any Docker Host that has access to your DHE instance: 218 219 $ docker pull dhe.yourdomain.com/ci-infrastructure/jnkns-img 220 latest: Pulling from dhe.yourdomain.com/ci-infrastructure/jnkns-img 221 511136ea3c5a: Pull complete 222 848d84b4b2ab: Pull complete 223 71d9d77ae89e: Pull complete 224 <truncated ouput...> 225 492ed3875e3e: Pull complete 226 fc0ab3008d40: Pull complete 227 dhe.yourdomain.com/ci-infrastructure/jnkns-img:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. 228 Status: Downloaded newer image for dhe.yourdomain.com/ci-infrastructure/jnkns-img:latest 229 230 You can view the traffic throughput while the custom image is being pulled from 231 the `System Health` tab in DHE: 232 233 ![DHE console pull throughput](../assets/console-pull.png) 234 235 Now that the `jnkns-img` image has been pulled locally from DHE, you can view it 236 in the output of the `docker images` command: 237 238 $ docker images 239 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 240 dhe.yourdomain.com/ci-infrastructure/jnkns-img latest fc0ab3008d40 8 minutes ago 674.5 MB 241 242 ## Launching a custom Jenkins container 243 244 Now that you’ve successfully pulled the customized Jenkins image from DHE, you 245 can create a container from it with the 246 [`docker run` command](https://docs.docker.com/reference/commandline/cli/#run): 247 248 249 $ docker run -p 1973:1973 --name jenkins01 dhe.yourdomain.com/ci-infrastructure/jnkns-img 250 /usr/share/jenkins/ref/init.groovy.d/tcp-slave-angent-port.groovy 251 /usr/share/jenkins/ref/init.groovy.d/tcp-slave-angent-port.groovy -> init.groovy.d/tcp-slave-angent-port.groovy 252 copy init.groovy.d/tcp-slave-angent-port.groovy to JENKINS_HOME 253 /usr/share/jenkins/ref/plugins/role-strategy.hpi 254 /usr/share/jenkins/ref/plugins/role-strategy.hpi -> plugins/role-strategy.hpi 255 copy plugins/role-strategy.hpi to JENKINS_HOME 256 /usr/share/jenkins/ref/plugins/dockerhub.hpi 257 /usr/share/jenkins/ref/plugins/dockerhub.hpi -> plugins/dockerhub.hpi 258 copy plugins/dockerhub.hpi to JENKINS_HOME 259 <truncated output...> 260 INFO: Jenkins is fully up and running 261 262 > **Note:** The `docker run` command above maps port 1973 in the container 263 > through to port 1973 on the host. This is the HTTPS port you specified in the 264 > Dockerfile earlier. If you specified a different HTTPS port in your 265 > Dockerfile, you will need to substitute this with the correct port numbers for 266 > your environment. 267 268 You can view the newly launched a container, called `jenkins01`, using the 269 [`docker ps` command](https://docs.docker.com/reference/commandline/cli/#ps): 270 271 $ docker ps 272 CONTAINER ID IMAGE COMMAND CREATED STATUS ...PORTS NAMES 273 2e5d2f068504 dhe.yourdomain.com/ci-infrastructure/jnkns-img:latest "/usr/local/bin/jenk About a minute ago Up About a minute 50000/tcp, 0.0.0.0:1973->1973/tcp jenkins01 274 275 276 ## Accessing the new Jenkins container 277 278 The previous `docker run` command mapped port `1973` on the container to port 279 `1973` on the Docker host, so the Jenkins Web UI can be accessed at 280 `https://<docker-host>:1973` (Don’t forget the `s` at the end of `https`.) 281 282 > **Note:** If you are using a self-signed certificate, you may get a security 283 > warning from your browser telling you that the certificate is self-signed and 284 > not trusted. You may wish to add the certificate to the trusted store in order 285 > to prevent further warnings in the future. 286 287 ![Jenkins landing page](../assets/jenkins-ui.png) 288 289 From within the Jenkins Web UI, navigate to `Manage Jenkins` (on the left-hand 290 pane) > `Manage Plugins` > `Installed`. The `Role-based Authorization Strategy` 291 plugin should be present with the `Uninstall` button available to the right. 292 293 ![Jenkins plugin manager](../assets/jenkins-plugins.png) 294 295 In another browser session, try to access Jenkins via the default HTTP port 8080 296 — `http://<docker-host>:8080`. This should result in a “connection timeout,” 297 showing that Jenkins is not available on its default port 8080 over HTTP. 298 299 This demonstration shows your Jenkins image has been configured correctly for 300 HTTPS access, your new plugin was added and is ready for use, and HTTP access 301 has been disabled. At this point, any member of your team can use `docker pull` 302 to access the image from your DHE instance, allowing them to access a 303 configured, secured Jenkins instance that can run on any infrastructure. 304 305 ## Next Steps 306 307 For more information on using DHE, take a look at the 308 [User's Guide](./userguide.md).