在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:tmlbl/docker-koa开源软件地址:https://github.com/tmlbl/docker-koa开源编程语言:JavaScript 79.3%开源软件介绍:Docker + Koaprerequisitesbuild.shRUN:
To create a docker container we need a docker image. Running the above command in this repository will build us an image that can execute node.js with the --harmony flag in order to run our koa application. The build command looks for a Dockerfile in the current directory. Here is our Dockerfile:
The FROM command specifies a local or pull-able image to use as a "base" for the new image. Subsequent commands will add "layers" to the final image
It is good practice to sign your images like this
Apt-get update almost always has to be run. Because you are starting with a very basic system, you must populate the source lists for your package manager in order to be able to download and install packages
We'll use the unix utility curl to download the node.js binaries
We're going to put our app's code in the /app folder
0.11.12 is the recommended node version for running koa
The ADD command copies the contents of the current directory (.) into the specified folder in the image
The node tool supervisor is a little too squirrely for production use, but can effectively crash and restart our node process on file changes during development
A container's ENTRYPOINT is the command that will be executed when a container instance of the image is started. Since we mounted an executable shell script into the /app folder, we can use it to "boot" our container Building your own image is fun, but the real power of docker is being able to upload and download versioned images, a lot like versioning code with git. For example, to download the latest version of this image, you can run the following command:
Because the repository tmlbl/koa has been uploaded to docker hub, you will be able to start downloading it immediately. The docker team maintains the docker hub and offers premium accounts, but it is also possible to create your own docker hub by running the docker-registry container and configuring docker to use that endpoint. up.sh
The docker run command creates a new docker container, which is an instance of a docker image. The image in the above command is the koa image we created above. Let's go through the flags one by one.
Runs the container in daemon mode, freeing up the current terminal
Maps the virtual port 3000 on the container to port 3000 on the host machine.
Mounts the data volume of the current directory, represented by the output of the
Sets the working directory inside the container to /app. Though we use an absolute path to start supervisor, it throws errors when trying to restart the script unless this is set.
This assigns a unique string identifier to our container. When running further docker commands, we can specify this container by the name "koa". By default, docker containers are given a unique alphanumeric identifier, but it is much more useful to assign them readable names. For example, we can now run:
Which will follow the tail of stdout from the container. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论