LoginSignup
2
1

DockerでUbuntu22.04のイメージを取得して起動するーDockerfile利用編

Last updated at Posted at 2024-03-02

はじめに

前回は、Dockerイメージをpullして、起動する方法を記事にしました。

今回は、Dockerfileを利用して、Dockerイメージを作成して、コンテナを起動する方法を記事にします。なお、作成するDockerイメージのタイムゾーンを日本時間に変更しています。

Dockerfile作成

# Use the official Ubuntu 22.04 base image
FROM ubuntu:22.04

# Set the timezone to Asia/Tokyo
RUN apt-get update
RUN apt-get install -y tzdata
RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

Dockerイメージ作成

docker build -t my-ubuntu22.04-image .

コンテナ起動

docker run -it -d --name my-ubuntu22.04-container my-ubuntu22.04-image 

コンテナに入る

docker exec -it my-ubuntu22.04-container /bin/bash

以上です。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1