[Google Cloud] Getting Started with Docker

I'll skip it until I get to the gcloud command line tools.

List active account names

gcloud auth list

output:

Credentialed accounts:
 - <myaccount>@<mydomain>.com (active)

List project IDs

gcloud config list project

output:

[core]
project = <project_ID>

Hello the world

docker run hello-world

Check the container image pulled from Dockerhub with Docker images

docker images

output

REPOSITORY     TAG      IMAGE ID       CREATED       SIZE
hello-world    latest   XXXXXXXXX      X days ago    X.XX kB

Display a list of running containers

docker ps

If you enter -a, containers that have not been started will also be displayed.

Build

Create a directory

mkdir test && cd test

Create a Dockerfile (omitted)

Create the source code file of the application (omitted)

Build the image

docker build -t [image name]:0.1 .

-t maps the image name to the tag name. name: tag If you do not define a tag name, it will be recorded as latest by default.

Run

docker run -p 4000:80 --name my-app [image name]:0.1

You can name the container name with --name.

Stop and rm the container

docker stop my-app && docker rm my-app

You can run the container in the background

docker run -p 4000:80 --name my-app -d [image name]:0.1

Use -d.

docker logs [container_id]

If you want to check the container log, execute the above command. If you can identify the container with the first few letters of container_id, you don't have to enter all the ids.

Modify the source code and upgrade the tag

docker build -t [image name]:0.2 .
docker run -p 8080:80 --name my-app-2 -d [image name]:0.2
curl http://localhost:8080

Check if the container was built correctly.

debug

docker logs -f [container_id]

If you want to check the log while moving the container, use -f.

Publish

Push your own image to Google Container Registry

[hostname]= gcr.io [project-id]= your project's ID [image]= your image name [tag]= any string tag of your choice. If unspecified, it defaults to "latest".

gcloud config list project

Find out the project ID.

docker tag [image name]:0.2 gcr.io/[project-id]/[image name]:0.2

Tag the image.

docker push gcr.io/[project-id]/[image name]:0.2

Push the image to gcr.

You can see the image pushed in Navigation menu> Container Registry. You can also check it at http://gcr.io/[project-id]/[image name].

docker stop $(docker ps -q)
docker rm $(docker ps -aq)

You can stop and delete the container in the development environment.

docker rmi [image name]:0.2 gcr.io/[project-id]/[image name] [image name]:0.1
docker rmi [image name]:[tag]
docker rmi $(docker images -aq)
docker images

After deleting the child image, delete the parent image.

docker pull gcr.io/[project-id]/[image name]:0.2
docker run -p 4000:80 -d gcr.io/[project-id]/[image name]:0.2
curl http://localhost:4000

If you want to start the container again in the development environment, docker pull the image stored by gcr and docker run.

Recommended Posts

[Google Cloud] Getting Started with Docker
Getting Started with Docker
Getting Started with Docker with VS Code
Getting Started with Docker for Mac (Installation)
Getting Started with DBUnit
Getting Started with Ruby
Getting Started with Swift
Getting Started with Doma-Transactions
Getting Started with Doma-Annotation Processing
Getting Started with Java Collection
Get started with DynamoDB with docker
Getting Started with JSP & Servlet
Getting Started with Java Basics
Getting Started with Spring Boot
Getting Started with Ruby Modules
Proceed with Rust official documentation on Docker container (1. Getting started)
Use Java 11 with Google Cloud Functions
Google Cloud Platform with Spring Boot 2.0.0
Getting started with Java lambda expressions
Microservices With Docker and Cloud Performance
Getting Started with GitHub Container Registry instead of Docker Hub
Getting Started with Doma-Criteria API Cheat Sheet
Getting Started with Ruby for Java Engineers
Getting Started with Parameterization Testing in JUnit
Getting Started with Ratpack (4)-Routing & Static Content
Getting started with the JVM's GC mechanism
Getting Started with Language Server Protocol with LSP4J
Getting Started with Creating Resource Bundles with ListResoueceBundle
Getting Started with Java_Chapter 8_About Instances and Classes
Links & memos for getting started with Java (for myself)
Getting Started with Doma-Using Projection with the Criteira API
Getting Started with Doma-Using Subqueries with the Criteria API
Getting Started with Java 1 Putting together similar things
Getting started with Kotlin to send to Java developers
Maybe it works! Let's get started with Docker!
Getting Started with Doma-Using Joins with the Criteira API
Getting Started with Doma-Introduction to the Criteria API
I tried Getting Started with Gradle on Heroku
Getting started with Java programs using Visual Studio Code
Launch MariaDB with Docker
Rails deploy with Docker
Explode Docker with WSL2
Operate Emby with Docker
Try WildFly with Docker
Use ngrok with Docker
Run Payara with Docker
[Docker] Connection with MySQL
Php settings with Docker
Getting Started with Legacy Java Engineers (Stream + Lambda Expression)
Get started with Gradle
Disposable PHP with Docker
Install Composer with Docker
Getting started with Java and creating an AsciiDoc editor with JavaFX
Getting Started with Doma-Dynamicly construct WHERE clauses with the Criteria API
Getting Started with Reactive Streams and the JDK 9 Flow API
How to get started with Gatsby (TypeScript) x Netlify x Docker
Pytorch execution environment with Docker
Use GDAL with Python with Docker
Deploy with EC2 / Docker / Laravel
Run TAO Core with Docker
Docker management with VS Code