Card 03/ 06
All 6 cards
WalkthroughDifficulty: Beginner1 min
From a Dockerfile to a Container You Can Open
A project with a Dockerfile in it, turned into something you can open.
Building an image and starting a container from it
Step 1 of 4
Build it
$ docker build -t my-api:1 .
[+] Building 12.4s (10/10) FINISHED
=> naming to docker.io/library/my-api:1-t my-api:1 names the result. The . is the build context: the directory sent to the builder, and the only place COPY can read from.
Check it exists
$ docker images my-api
REPOSITORY TAG IMAGE ID SIZE
my-api 1 7b1e4c9a2f30 142MBRun it
$ docker run -d --name api -p 3000:3000 my-api:1
$ curl -s localhost:3000/health
{"status":"ok"}Change something and build again
$ docker build -t my-api:2 .
$ docker run -d --name api2 -p 3001:3000 my-api:2A new tag rather than the same one. The old image is still there, still runnable, which is what makes going back cheap.