LoginSignup
3

More than 3 years have passed since last update.

Dockerfile作成〜コンテナに入るまでのコマンド(備忘録)

Last updated at Posted at 2018-09-05

環境

  • OS : macOS High Sierra 10.13.6
  • Docker : Docker for Mac 18.06.1-ce-mac73
    • Base Image : CentOS7
    • Nodebrew : v9.11.1

手順

Dockerfileの作成

Dockerfile
FROM centos:centos7

# epel
RUN yum -y install epel-release

# utilities
RUN yum -y install wget which

# git
RUN yum -y install git

# nodebrew + node.js
ENV NODE_VERSION v9.11.1
RUN wget git.io/nodebrew
RUN perl nodebrew setup
ENV PATH $HOME/.nodebrew/current/bin:$PATH
RUN echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> $HOME/.bashrc
RUN source $HOME/.bashrc && nodebrew install-binary $NODE_VERSION
RUN source $HOME/.bashrc && nodebrew use $NODE_VERSION

イメージのビルド

$ docker build -t n11sh1/nodebrew:v9.11.1 .

イメージの確認

$ docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
n11sh1/nodebrew        v9.11.1             218058a47150        2 minutes ago       708MB

コンテナの起動

$ docker run -it -d --name nodebrew n11sh1/nodebrew:v9.11.1

コンテナの状態確認

$ docker ps
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS              PORTS               NAMES
13bc5afc4dcc        n11sh1/nodebrew:v9.11.1   "/bin/bash"         10 seconds ago      Up 8 seconds                            nodebrew

コンテナに接続

$ docker exec -it nodebrew bash
[root@13bc5afc4dcc /]# 

後処理

コンテナの停止

$ docker stop nodebrew

コンテナの削除

$ docker rm nodebrew

イメージの削除

$ docker rmi -f :image_id

さいごに

個人ブログにオリジナル(日本語&英語)をUPしています。
この記事が良いと感じた方は、そちらにもリアクション頂けると嬉しいです:relaxed:
https://blog.n11sh1.com

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
3