🐳ハローワールドプログラム


DockerでHello World Appの例を実行すると、非常に簡単ですし、コードの1行を書くことなく行うことができます.必要なのはDocker Runコマンドです.この記事では、DockerハブからDockerイメージをダウンロードし、Dockerイメージを実行してDockerコンテナを起動する方法を学びます.
そこで、私たちは主にDocker引きとDocker RunコマンドでこのDockerチュートリアルで働きます.我々は今後のチュートリアルでこれらのコマンドをカバーする心配しないでください.
ハローワールドプログラム
Dockerは、CプログラムHelloであなたのための裸の最小の容器をセットアップするサンプルHello World Appを提供します.Cが実行され、次のコードが実行されます.
#include <sys/syscall.h>
#include <unistd.h>

#ifndef DOCKER_IMAGE
    #define DOCKER_IMAGE "hello-world"
#endif

#ifndef DOCKER_GREETING
    #define DOCKER_GREETING "Hello from Docker!"
#endif

#ifndef DOCKER_ARCH
    #define DOCKER_ARCH "amd64"
#endif

const char message[] =
    "\n"
    DOCKER_GREETING "\n"
    "This message shows that your installation appears to be working correctly.\n"
    "\n"
    "To generate this message, Docker took the following steps:\n"
    " 1. The Docker client contacted the Docker daemon.\n"
    " 2. The Docker daemon pulled the \"" DOCKER_IMAGE "\" image from the Docker Hub.\n"
    "    (" DOCKER_ARCH ")\n"
    " 3. The Docker daemon created a new container from that image which runs the\n"
    "    executable that produces the output you are currently reading.\n"
    " 4. The Docker daemon streamed that output to the Docker client, which sent it\n"
    "    to your terminal.\n"
    "\n"
    "To try something more ambitious, you can run an Ubuntu container with:\n"
    " $ docker run -it ubuntu bash\n"
    "\n"
    "Share images, automate workflows, and more with a free Docker ID:\n"
    " https://hub.docker.com/\n"
    "\n"
    "For more examples and ideas, visit:\n"
    " https://docs.docker.com/get-started/\n"
    "\n";

int main() {
    //write(1, message, sizeof(message) - 1);
    syscall(SYS_write, STDOUT_FILENO, message, sizeof(message) - 1);

    //_exit(0);
    //syscall(SYS_exit, 0);
    return 0;
}
上記のコードは、ちょうどあなたのプログラムは、ハローワールドのアプリを実行するのアイデアを与えることです.私たちがDockerコンテナがどのように動くかについて理解するためにここにいるので、それを理解することに時間を浪費する必要はありません.
実行Dockerこんにちは世界アプリ
端末( Mac OSを使用している場合)やコマンドプロンプトを開き、以下のコマンドを実行します.
docker run hello-world

//Output

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
Status: Downloaded newer image for hello-world:latest


Hello from Docker!
This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.


To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/


For more examples and ideas, visit:
https://docs.docker.com/get-started/
我々は新鮮なDockerのインストールを持っているし、我々は任意のコードを書いていない、我々はいずれかのプロジェクトをダウンロードしていないし、どのように上記のコマンドは、hello world appを実行しますか?デフォルトのDockerのインストールで利用できますか?
さて、答えはNOです、我々はコードを持っていないか、世界のアプリのDocker用語Dockerイメージではありません.しかし、私たちがDocker Runコマンドを実行するとき、DockerはDockerイメージを捜します、この場合、Hello Worldローカルの名前でDockerイメージを捜します、そして、イメージが見つけられないならば、Dockerはインターネット上でDocker Hubと接続して、イメージをダウンロードして、それを走らせます.
このシリーズの他の記事をチェックしてください:Dockerチュートリアル
1).Introduction to Docker and Docker Containers
2).Ultimate Comparision between Docker Containers vs Virtual Machine
3).Complete Setup to Install Docker
4).Hello World Program in Docker
5)3 Simple Steps to Deploy on Docker