Docker with boot2docker for Windows Tutorial
This tutorial walks you through the basics of using a Java app server (WildFly) via a Linux container, running on Windows with boot2docker. We have been testing this tutorial on Windows 7 and 8.1, you will notice that the screenshots come from either of those versions as this document has been tested and maintained.
There are notes for people running on Macs as well.
First follow installation steps for boot2docker:
Unless you already have VirtualBox installed, install all the components.
Mac: The docker and boot2docker binaries are in
/usr/local/bin
which you can access from your terminal. Windows: The boot2docker binary lands inC:\Program Files\Boot2Docker
for Windows
Tip 1: where does the boot2docker VM ISO land on a Windows?
Windows: C:\Users\Burr\.boot2docker\boot2docker.iso
Mac: ~/.boot2docker/boot2docker.iso
Tip 2: where does the boot2docker instance land on Windows installation of VirtualBox
C:\Users\Burr\VirtualBox VMs\boot2docker-vm
Tip 3: Window Size Width 160 - docker ps is best displayed with lots of width
You can make this change on the Boot2Docker Start command window as well
Tip 4: VirtualBox before boot2docker init
VirtualBox installed prior to boot2docker has no mention of boot2docker until we use
boot2docker init
. Also, if you have previously installed boot2docker, you can often useboot2docker upgrade
to simply update to the latest version.
Explore Docker
-
Look for and select the
Boot2Docker Start
menu option in your Start MenuOr use start.sh to launch the command prompt (not the normal Windows command prompt)
You should be able to double-click on start.sh in C:\Program Files\Boot2Docker for Windows
If you successfully launch start.sh, it will execute
up
,status
andip
, therefore you can skip to step 8 below. Do make note of the IP address that is printed out, you will need it later.If there are error messages (and there normally are for a brand new installation), read steps 2 through 7 for some alternative ways to get boot2docker up and happy
-
You might also execute boot2docker commands from the Windows (DOS) Command Prompt aka "cmd.exe" and type
boot2docker version
Note: We have seen this fail on some systems. There will be some workarounds listed in step 3 below.
Tip: on Windows 8.1, the Command Prompt is accessible if you hit the Windows key and X then C on the keyboard
-
You should see the boot2docker-vm listed in VirtualBox Manager
Note: This might result in
error in run: Error generating new SSH Key into C:\Users\Burr\.ssh\id_boot2docker: exec: "ssh-keygen": executable file not found in %PATH%
If so, then fall back to the Boot2Docker Start menu option calling "start.sh".
There is another SSH related error that shows up, basically ssh.exe can not be found in the %PATH%. Use Control Panel to add the C:\Program Files(x86)\Git\bin to your PATH
-
boot2docker up
Look for the following on Windows:
Now, if you check the VirtualBox GUI you will see the
boot2docker-vm
running:Watch out for "VT-x is disabled in BIOS" errors If virtualization has not been enabled in your machines BIOS, you could see the following error:
Or, if you hit the Start button inside the VirtualBox Manager directly
If you see this error, you will need to update your BIOS settings accordingly.
BIOS for Lenovo T440s
Watch for the following on Mac OSX:
Copy and paste the export statements you are provided with in to your terminal. If you get this step wrong, when you try further commands, you may see an error message like:
-
boot2docker status
Note: When it is time to shutdown, run
boot2docker down
-
You will need this later!
-
From this point forward, you will be inside of a Linux shell, using Linux commands
-
docker version
-
docker images
-
docker run centos /bin/echo "Hello World"
This will take some time if this is the first run of the "centos" image
If you run the same command again, you will notice that is runs immediately, no download required. A Docker container starts incredibly fast when compared to traditional virtual machine technology.
To prove that point, run the same command again.
Note: the container stops as soon as it finishes the /bin/echo command
-
On Windows, with boot2docker 1.3.x, the Users directory is shared as
/c/Users
This shared folder will allow you to add and edit files using your traditional Windows tools instead of having to learn vi or nano.
Using your File Explorer, create a
demo
sub-directory to your home directory and then use als -l
to see it via the boot2docker-vm (in this exampleBurr
is the username):ls -l /c/Users/Burr/demo
In this screenshot, I already some sample projects in my C:\Users\Burr\demo directory
Note: We won't be using "demo" in this tutorial, the goal here was to let you see the connection between /c/Users and C:\Users
-
docker run -i -t centos /bin/bash
-i means interactive and -t allows your keyboard input
You can also use
-it
as well as-i -t
. Remember this trick - if you have an app server failing to start, you can see the console output and review the logs by using "-it"If this is your first time running the centos image, it may take over a minute to download.
You are now running inside of the Centos-based container, to prove that point, use the following command
cat /etc/system-release
Type
exit
to leave the container and drop back into the boot2docker-vm shell. -
docker ps
There should be no currently running containers since
exit
terminated the last centos container -
docker ps -a
but there have been previously run containers
-
docker images
-
docker pull centos/wildfly
Docker Hub contains a large number of pre-configured images that are ready to use via a simple "pull" e.g. https://registry.hub.docker.com/u/centos/wildfly/
run
does an implicit "pull" if the image is not already downloadedDocker images are typically identified by two words
"owner"/"imagename"
Thecentos/wildfly
image includes nice documentation on how to use it - we will be following several of those steps next. -
docker run -it centos/wildfly
The
t
is important so you canCtrl-C
to stop wildfly and the container.Hit
Ctrl-C
and run adocker ps
to see that the container has been stopped.In this particular case, the WildFly instance does not expose any ports to the outside world, let's try that next.
-
docker run -it -p 8080:8080 centos/wildfly
If you remember the IP address you can use your favorite browser to hit the server. If you forgot to make note of your IP address earlier, you can open another session into boot2docker. Just go back to the Windows Start menu and select
Boot2Docker Start
or run start.sh. You might wish to keep both boot2docker sessions open as it allows you to docker run an app server via "-it" in one window and then "docker ps" or "docker logs" in another window.Press
Ctrl-C
to terminate the WildFly container. -
docker history centos/wildfly
The history command allows you to see more detail into how the image was crafted
Modify the image and provide our own custom Java application
-
If you remember way back to
ls /c/Users/Burr/demo
, theUsers
directory on your Windows host is shared with the boot2docker-vm (thanks to VirtualBox Guest Additions). In your home directory, create a directory calleddocker_projects
that is a sibling ofdemo
. You can create the directory from within the boot2docker-vm with the following command (or just use File Explorer).mkdir /c/Users/Burr/docker_projects
Use your home directory name in place of "Burr"
and then create a sub-directory called
myapp
mkdir /c/Users/Burr/docker_projects/myapp
You can create the "myapp" directory via Windows Explorer or the boot2docker-vm shell
and then change to the directory, it is important that you do this inside of the boot2docker-vm shell
cd /c/Users/Burr/docker_projects/myapp
-
In the
myapp
directory, create a text file calledDockerfile
, with no extension.On Windows you might use the Atom editor from Atom.io for text editing.
-
Edit the newly created
Dockerfile
and add the following two lines:FROM centos/wildfly COPY javaee6angularjs.war /opt/wildfly/standalone/deployments/
Note: On Macs, we have seen Wildfly have a permissions problem with the .war. The workaround is to switch to Root and use chown to make the ajustment to the .war file by adding the following two lines:
USER root RUN chown wildfly:wildfly /opt/wildfly/standalone/deployments/javaee6angularjs.war
The trailing "/" does matter
You can find
javaee6angularjs.war
athttps://github.com/burrsutter/docker_tutorial/blob/master/javaee6angularjs.war?raw=trueDownload the war and copy it to themyapp
directory. -
Back in the boot2docker ssh session
docker build --tag=myapp .
the trailing "." is important
Use the docker
docker images
command to see if the image was created -
Let's see if that worked
docker run -it -p 8080:8080 myapp
you should see the deployment of
javaee6angularjs.war
in the wildfly console logging -
And test the app via your browser http://192.168.59.105:8080/javaee6angularjs
The IP address in my screenshots change from time to time as this document has been maintained. Just make sure to remember YOUR IP address as seen via start.sh or boot2docker ip
Now it is time for a victory dance around the room! You have your first Java EE application deployed as part of a Docker container. Remember, Ctrl-C to shut down the app server.
Extra Credit
-
Run detached
You could also use a
-d
instead of-it
to run the container detached, in the backgrounddocker run -d -p 8080:8080 myapp
If detached, you will need to use
docker ps
to see the active containers and then usedocker stop CONTAINER_ID
anddocker rm CONTAINER_ID
Note: Docker automatically generated the name "agitated_hawking" which you can use instead of the CONTAINER_ID
-
Container naming
Adding a --name=some_name allows you to give override the default name of agitated_hawking or whatever was randomly assigned to your container by Docker
docker run --name=myapp_is_running -d -p 8080:8080 myapp
-
Viewing logs
docker logs myapp_is_running
and you can
docker stop myapp_is_running
when it is time to shutdown the -d detached app server container -
Dive into a live container
docker exec -it myapp_is_running bash cd /opt/wildfly/standalone/log tail server.log
This is a very useful technique if you find things are misbehaving and you wish poke around inside the running container.
Cleanup
OPTIONAL - Clean Slate: If you wish to completely clean up and run through the above steps again:
-
Remove/Delete all containers
docker rm `docker ps -a -q`
the back ticks are important! You might also need to "stop" or "kill" any containers that are running and will not remove.
docker ps -a docker stop CONTAINER_ID docker kill CONTAINER_ID
Replace CONTAINER_ID with the id seen in the
docker ps
results. -
Remove/Delete all images
docker rmi `docker images -a -q`
watch those back ticks again
-
Exit the boot2docker-vm shell, back at the Windows Command Prompt
boot2docker down boot2docker destroy
or if boot2docker from the command line is causing you problems, there is "Delete Boot2Docker VM" Start menu option which maps to delete.sh
and to re-make the boot2docker-vm
boot2docker init boot2docker up
On Windows
C:\Users\burr\.boot2docker
contain files associated with your installation and I have seen .boot2docker not be uninstalled properly, manual deletion may be necessary
Check out the follow-on tutorial for adding MySQL.https://github.com/burrsutter/docker_mysql_tutorial
from:https://github.com/burrsutter/docker_tutorial
相关推荐
Docker for Windows Installer.exe The fastest and easiest way to get started with Docker on Windows 2018-03-08 最新上传
Install Docker Desktop on Windows 官网下载太慢了,给同样辛苦找下载地址的小伙伴分享下我下的资源
2. DOCKER – INSTALLING DOCKER ON LINUX Docker Version Docker Info Docker for Windows Docker ToolBox 3. DOCKER ─ INSTALLATION Docker for Windows Docker ToolBox Working with Docker Toolbox
Docker是一种开源的应用容器引擎,它允许开发者打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux或Windows机器上,也可以实现虚拟化。Docker容器完全隔离,互不影响,同时又可以共享主机...
Docker官网windows版一键安装工具,包含virtualbox(如果你已经安装virtualbox,则自动升级)...The Docker Toolbox is an installer to quickly and easily install and setup a Docker environment on your computer.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 或者在程序和功能选中 WSL。 2. 下载 Centos 7 的docker 镜像 可以参考 ...
一个基于Electron + Vue.js构建的Dockeron项目。 模板生成器: Docker Engine API: 。 UI组件: 我仅使用Mac版本,这意味着要测试Windows和Linux版本。 请注意,该项目仍在积极开发中,许多功能或特性尚未实现...
在本文中,我们将详细探讨如何在Windows 10上安装WSL2(Windows Subsystem for Linux 2)以及Ubuntu 20.04,并进一步设置Docker环境。这对于开发者来说是一个非常实用的过程,因为它允许在Windows环境下运行原生的...
For Docker to be installed successfully on Windows, certain system requirements must be met: 1. **Windows Version**: Windows 10 Pro, Enterprise, or Education (version 1803 or later). 2. **Processor*...
iis Windows Nano服务器上的IIS 该项目全部涉及... 入门Windows 10 Physical Machine or Virtual Machine Install Docker for 1.13.0-beta39 on your Windows 10 machine. Windows Server 2016 Register into Microso
同时,它还支持与其他工具如Maven、Gradle、Docker等的联动,以实现完整的构建、测试和部署流程。 总的来说,安装Jenkins on Windows是一个相对简单的过程,主要涉及JDK的安装、Jenkins安装程序的运行、管理员密码...
win - Install OpenPLC on Windows over Cygwin linux - Install OpenPLC on a Debian-based Linux distribution docker - Used by the Dockerfile (i.e. doesn't invoke sudo) rpi - Install OpenPLC on a ...
122 RAC Guides安装指南_Rac11gR2OnWindows 123 RAC Install_Oracel_RAC_12.2.0.1_on_Oracle_Linux_6.5 124 RAC Install_Oracel_RAC_12.2.0.1_on_Oracle_Linux_6.5 125 RAC Installation walk-through - Oracle ...
We install and run Caffe on Ubuntu 16.04–12.04, OS X 10.11–10.8, and through Docker and AWS. The official Makefile and Makefile.config build are complemented by a community CMake build. Step-by-...
以下是一些关于“Ruby on Windows”的关键知识点: 1. **安装Ruby**: - `rubyinstaller-2.4.1-2-x64.7z` 是Ruby的一个Windows安装程序,它是RubyInstaller项目的一部分。这个7z文件包含了64位版本的Ruby 2.4.1,...
Enable-WindowsOptionalFeature - Online - FeatureName Microsoft - Windows - Subsystem - Linux Enable-WindowsOptionalFeature - Online - FeatureName VirtualMachinePlatform wsl -- set-default - version 2...
[OnlyOffice DocumentServer安装指南](https://helpcenter.onlyoffice.com/installation/workspace-install-windows.aspx) - 在配置 PostgreSQL 数据库时,如果已按照上述步骤完成,则可以保持默认设置;对于 ...
Restart=on-failure [Install] WantedBy=multi-user.target ``` 这里,`ExecStart`和`ExecStop`指定了启动和停止服务的脚本路径,`Restart`参数决定了服务失败时的行为。 3. **模拟启动服务**:使用安装的...
本文将详细介绍如何在Windows 7/XP 32位系统上,利用XAMPP集成环境安装和配置BugFree 3.0。 **一、XAMPP简介与安装** XAMPP是一款免费的、跨平台的Apache服务器集成包,包含了Apache HTTP服务器、MySQL数据库、PHP...