[First time]Display “Hello World” by Docker

tomomemo
2 min readMar 1, 2021

For first-time users of Docker. We would like to display “Hello world” in a web browser.

Sourced by https://icon-library.com/

Using PC: Macbook

First of all, You have to prepare this.

You need to download “Docker Desktop for Mac” from this link.

And I used this repository. Thank you so much!!

https://github.com/zoetrope/training-docker

Moving to Hello world.

$ cd /Users/yourName/yourDirectory/training-docker/02_dockerfile/helloworld

Let’s create a Docker image from a Dockerfile.

docker build -t [Image name to generate]:[tags] [Place of Dockerfile(omission)]

$ docker build -t helloworld:v1 .

Then, you’ll get this message in the terminal.

[+] Building 55.1s (8/8) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 362B 0.0s=> [internal] load .dockerignore 0.0s=> => transferring context: 48B

This file is a container that installs Node.js on Ubuntu and starts an HTTP server.

Second, I’ll check to see if the Docker Image is ready.

$ docker images

You know It shows a lot of things in the terminal.

I’m not going to tell you what it says, but it shows a lot of stuff. Looks like it’s done.

Finally, Let’s run Docker.

$ docker run -d — name hellowold -p 3000:3000 helloworld:v1$ curl localhost:3000>Hello World

Yeah!! Hello World!! Then, we have to take care spelling “hello wold”. The file was originally created like this.

We would like to check out a Web browser.

localhost:3000

That’s my man!

I’ve put together a list of commonly used Docker commands.

docker images : Create docker images from docker files.docker build : Building the docker imagesdocker run : Run the containerdocker stop : Stop the containerdocker rm : Remove the containerdocker ps : Check out the container docker inspect : Get information details from the container

You have to make sure you stop it. If you run it in a local environment, it will stay running unless you stop it. And If you don’t need the container anymore, I recommend you delete it frequently.

[Side note]

You should use the Lint tool when using Docker. Using “hadolint”. It means a tool that analyzes problems in your code. It’s like ES lint by vscode in Javascript.

$ docker run — rm -i hadolint/hadolint < Dockerfile¥

Enjoy coding!!!

--

--

tomomemo
0 Followers

Re:Life in developing from ZERO. | Web developer.