miercuri, 25 noiembrie 2015

Create and run a Docker image from Dockerfile on Windows via Command Prompt

! INSTEAD OF anghelleonard USE YOUR NAME

As you may know from the previous post (Create a new Docker machine on Windows via Command Prompt), I've created a Docker machine named my-machine.

1. Now, I want to create an image on my-machine. For this, I need to write a Dockerfile using the Docker commands (see Docker Reference). My image will be pretty simple, and it will consist in a Docker image for running OmniFaces Showcase WAR under WildFly 8.2.0 Final. So, I need the following commands; this is the content of my Dockerfile:

FROM jboss/wildfly:8.2.0.Final

MAINTAINER Anghel Leonard

CMD ["/opt/jboss/wildfly/bin/", "-c", "standalone-full.xml", "-b", ""]

RUN curl -L -o /opt/jboss/wildfly/standalone/deployments/Showcase.war


Putting this in words, sound like this: give me the WildFly 8.2.0 Final server in standalone mode, and deploy and expose on port 8080 the OmniFaces Showcase WAR.

2. The my-machine is not running, so I need to start it and get the environment commands:

Command: docker-machine start my-machine
Command: docker-machine env --shell cmd my-machine
Command: FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd my-machine') DO %i   

3. Before I build this image, I checked to see if I have any images or containers running. This is just a check, not a mandatory step:

- list of available images
Command: docker images

- list of available running containers
Command: docker ps

- list of recently containers activity
Command: docker ps -a

Since this is a new machine, I have no images or containers (running/history):

3. In order to obtain the image from the above Dockerfile, I need to build that file. So, I navigated to the Dockerfile location and execute the below command (my image name will be anghelleonard/omnifaceswildfly). This step will take some time depending on your Interner connection since the image is built by downloading the WildFly and OmniFaces Showcase from the Internet. Well, at further uses, these resources will be taken by default from cache.

Command: docker build -t anghelleonard/omnifaceswildfly .

4. Now, I want to see if the image was created. As you can see in the below figure, I have two images, one is jboss/wildfly (run only the WildFly container) and the other one is anghelleonard/omnifaceswildfly:

Command: docker images

5. Further, I can run and test my image, anghelleonard/omnifaceswildfly. For this, I will need the below command (notice in figure below that WildFly has started and the OmniFaces Showcase application was deployed successfullly):

Command: docker run -t -p 8080:8080 anghelleonard/omnifaceswildfly

6. Open your browser and type in browser address bar: You should see the WildFly welcome page from below:

Now, add /Showcase to this URL: You should see the OmniFaces Showcase running as below:

Note The is the Docker host (this may differ in your test). You can easily pick up this IP via the below command. You can easily gain the Command Prompt control by pressing the CTRL+C. Don't worry, this will not stop WildFly!

Command: env | greep DOCKER

7. You can check to see the currently running containers (you can easily identify our container):

Command: docker ps

8. If you check carefully the above image, you can notice that our container is named, dreamy_leavitt (this may differ in your case since Docker has randomly generated it).  This is a Docker convention for naming containers when we don't indicate explicitly a name. This name can be useful for many furher operations, like stopping the container:

Command: docker stop dreamy_leavitt

You can easily check that the container has stopped by trying to refresh the or by running again the docker ps command (as you can see from the below image, there is no container running):

However, you can still check the containers running history via, docker ps -a command.

9. For now, we finish this Docker lesson by stopping the machine. In the next post, you will see how I've pushed this image on DockerHub.

Command: docker-machine stop my-machine

Note: In order to see all the options for docker-machine command try:

Command: docker-machine --help

luni, 16 noiembrie 2015

Create a new Docker machine on Windows via Command Prompt

As you may know from the previous post (How I've installed Docker on Windows 7), I've just installed Docker on my Windows. Now, if you are in my case also, and you want to create a new Docker machine, here it is how I did it:

1. In order to create a new Docker machine via Windows Command Prompt, you need to set the ssh.exe in your PATH environment variable. This is in the Git\bin\ folder, which is commonly installed in C:\Program Files or C:\Program Files(x86).So, I opened a new Command Prompt, and add ssh.exe in PATH.

Command: set PATH=%PATH%; C:\Program Files\Git\bin

2. Further, we can list the existing Docker machines like this (we do this now, and after we add the new machine). As you can see, I have a single Docker machine, the default one.

Command: docker-machine ls

3. Now, I will use the same virtualbox driver to create a new machine named, my-machine.

Command: docker-machine create --driver virtualbox my-machine

4. Further, we need to connect the Docker with this machine.

Command: docker-machine env my-machine

5. Next, get the environment commands for my-machine.

Command: docker-machine env --shell cmd my-machine

6.This points a new command as you can see in the above picture.

Command: FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd my-machine') DO %i

7. Run the hello-world container.

Command: docker run hello-world


You can list the Docker machines again and notice that my-machine is active and running:

You can easy stop/start the Docker machine:

Command start: docker-machine stop my-machine
Command stop: docker-machine start my-machine

Note: In order to see all the options for docker-machine command try:

Command: docker-machine --help

marți, 10 noiembrie 2015

How I've installed Docker on Windows

How I've installed Docker on Windows ?

2. The big button labeled Download (Windows) was exactly what I was looking for. The download started directly (nice, no intermediate steps). After download I obtained an exe:

3. Obviously, I run the exe file. The welcome page appears like below (personally, I've un-ticked the checkbox - is my first Docker hit :) so help to improve is faaar away). Click on Next:

4. Nothing fancy further, the usual way to set up the local path for installing the new software (I've selected D:\DockerToolbox, you can select whatever you find convenient). Click Next.

5. Well, now I was asked to select the Docker components to be installed. Since I'm not familiar with Docker I'll go with the default selections and click Next:

6. Some additional tasks very common to Windows apps. Click Next:

7. Ready to install! Final report! Click Finish!

8. And ... here we go! During installation I was agree with installing a few Oracle add-ons also.

9. Finally, it looks like I've done a good job.

Well, now I was impatient to start doing something. Actually to run the first test, running the first container:

docker run hello-world

But, where to write this? Well, I've checkout my desktop and found these icons:

Docker Quickstart Terminal sound good! Since I did not have any machine, Docker tried to install one for me named, default. Unfortunately, my enthusiasm was shot down by an error related to the virtualization disabled. It looks like Docker want this enabled!

I had a small free inspection tool installed named, Speccy. Run it, switch to CPU tab and here we go, virtualization supported, but disabled:

Ok! Restart, go to bios, find the security setting and enable it. With virtualization enabled, tried again the Docker Quickstart Terminal. Well, total success! After doing its job, Docker reported that the default machine was created and is running, so I was opened the Docker VirtualBox Manager and spot it there:

Click on Show button and finally run the hello-world container. Total success again:

This was fun! Next, I'll try to put an Ubuntu machine here.