Install and build Nodejs webapp under Docker windows



1. About Docker

What is Docker? Docker is written in go language and is an open source application container engine. It allows developers to quickly package their applications and dependencies into a packaged and portable container Image, and then publish them to any popular machine (Linux, windows, Mac, etc.), and can also achieve virtualization. Containers use a completely independent sandbox mechanism and do not have any interface with each other. Multiple Containers can be run at the same time without interfering with each other, which is very useful for system testing in multiple environments, but the application of Docker is much more than that.

 

2. Installation

1. It is recommended to use Docker toolbox to install under Windows 7 system, which is simple, rude, quick and easy!

    https://www.docker.com/products/docker-toolbox

 Docker Coumunity Edition for Windows 10 

    http://get.daocloud.io/#install-docker-for-mac-windows 

    https://www.docker .com/community-edition#/windows

2. Because win7 systems are currently the majority, directly introduce Docker toolbox: Docker

toolbox is a tool set, which mainly includes the following contents:

     1. Docker CLI client, used to run the docker engine to create Images and containers

     2. Docker Machine. Allows you to run docker engine commands from the Windows command line

     3. Docker Compose. Used to run docker-compose commands

     . 4. Kitematic. This is the GUI version

     of Docker. 5. Docker QuickStart shell. This is a command line environment with Docker already configured.     6.

     Oracle VM Virtualbox.

The daemon uses the Linux kernel, so we cannot directly run the docker engine in windows. Instead, you need to run the Docker Machine command docker-machine, create and get a Linux virtual machine on your machine,

    use this virtual machine to run Docker engine on your windows system

3. Preparation:

Windows 7 and 10 x64, Support Hyper-V

 

4. Install Docker Toolbox

 

After the download is complete, install it.  

    In this step, you will install Docker Toolbox. After installation, the following software will be installed on your system:

    1. Docker client for Windows

    2. Docker Toolbox management tool and ISO image

    3. Oracle VM Virtualbox

    4. Git MSYS-git Unix tool

5. Confirm whether the installation is successful

  . Install When done, you will see three new icons on your computer desktop

    

  Double-click the Docker Quickstart Terminal icon to start a terminal

  . The first time you start it, you will see something output from the command line. Wait a minute, it will configure the Docker Toolbox, and then, when it finishes, you will see the startup success screen.

  If The bash interface prompts that there is no boot2docker image and needs to be downloaded on github. The prompt is as follows.

 

  This is because the default boot2docker image is not found. Download.

It should be noted here that different docker versions should preferably correspond to the same boot2docker version. I believe that everyone who opens the github download page should notice it. Finally, I found that there is no need to download,

there is a boot2docker in the root directory of DockerToolbox installed at the beginning, and it can be inferred that it is the corresponding version.

    

  Copy boot2docker.iso to the directory that bash prompts cannot be found (I am C:\Users\Administrator\.docker\machine\cache here).

  Then double-click the Docker Quickstart Terminal icon again, and the following interface appears, indicating that the installation is successful.

 

 

 Enter docker run hello-world on the command line and press Enter. If the docker configuration is successful, you will see the following output on the command line:

 

The docker environment configuration is completed under windows.

 

3. Build an image of a simple webApp that includes a Nodejs environment

1. Configure Nodejs environment locally (refer to nodejs official website: https://nodejs.org/en/download/)

2. Go to express official website to download generator

reference steps: http://expressjs.com/en/starter/generator.html

3. After installation, in the corresponding express application folder such as C:/myspp:

create a new file Dockerfile, copy the following code

# Express-App## VERSION 1.0.0

FROM node:latest

RUN mkdir -p /home/www/express- appWORKDIR /home/www/express-app

COPY . /home/www/express-appRUN npm install

EXPOSE 3000CMD ["npm", "start"]

 

Then double-click the desktop DockerQuickStartTerminal icon to enter the DockerTerminal interface:

 

 

jump to the one you just installed Express application file path: cd C:/myapp

 

Note that the slash of the file path in Docker Terminal is reversed, which is different from the path copied directly, and it must be changed to a backslash, otherwise docker will not be able to jump.

Then enter: docker build -t myapp . (note the dots behind)

 

The results are as follows:

 

 

 

 Seeing successfully build ***** means that the image build was successful.

Then verify whether the image already exists: docker images

 

You can view the image construction process through dicker history: docker history myapp

 

 

Then run the image: docker run -p 3000:3000 myapp

 

If you want to let the docker terminal run in the background: Add to the parameter -d

You can view the running status through docker ps:

 

 

 Enter: 192.168.99.100:3000 in the local browser to view the running app: (note that when using docker toolbox, instead of using 127.0.0.1, you need to use the ip address assigned when starting docker )

 

 

Check the browser webapp operation:

 

 Reference document: https://www.cnblogs.com/lujiangping/p/7206503.html

                   http://www.jb51.net/article/104251.htm

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326484263&siteId=291194637