LoginSignup
3
3

More than 3 years have passed since last update.

はじめてのdocker

Posted at

勉強前イメージ

知ってはいるけど、触ったことないし最初難しそう....

dockerのインストール・設定

  • インストール
yum update
yum search docker
yum install -y docker
  • dockerの起動・自動起動設定
systemctl start docker
systemctl enable docker
  • バージョン確認
docker -v

ubuntuの環境を立ててみる

  • ubuntuのコンテナを検索
docker search ubuntu
==========
INDEX       NAME                                                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/ubuntu                                                    Ubuntu is a Debian-based Linux operating s...   11721     [OK]       
docker.io   docker.io/dorowu/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interfac...   487                  [OK]
docker.io   docker.io/websphere-liberty                                         WebSphere Liberty multi-architecture image...   266       [OK]       
docker.io   docker.io/rastasheep/ubuntu-sshd                                    Dockerized SSH service, built on top of of...   250                  [OK]
docker.io   docker.io/consol/ubuntu-xfce-vnc                                    Ubuntu container with "headless" VNC sessi...   231                  [OK]
docker.io   docker.io/ubuntu-upstart                                            Upstart is an event-based replacement for ...   110       [OK]       
docker.io   docker.io/neurodebian                                               NeuroDebian provides neuroscience research...   78        [OK]       
docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          50                   [OK]
docker.io   docker.io/ubuntu-debootstrap                                        debootstrap --variant=minbase --components...   44        [OK]       
docker.io   docker.io/open-liberty                                              Open Liberty multi-architecture images bas...   42        [OK]       
docker.io   docker.io/i386/ubuntu                                               Ubuntu is a Debian-based Linux operating s...   24                   
docker.io   docker.io/nuagebec/ubuntu                                           Simple always updated Ubuntu docker images...   24                   [OK]
docker.io   docker.io/1and1internet/ubuntu-16-apache-php-5.6                    ubuntu-16-apache-php-5.6                        14                   [OK]
docker.io   docker.io/1and1internet/ubuntu-16-apache-php-7.0                    ubuntu-16-apache-php-7.0                        13                   [OK]
docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       11                   [OK]
docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4         ubuntu-16-nginx-php-5.6-wordpress-4             8                    [OK]
docker.io   docker.io/1and1internet/ubuntu-16-apache-php-7.1                    ubuntu-16-apache-php-7.1                        6                    [OK]
docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-7.0                     ubuntu-16-nginx-php-7.0                         4                    [OK]
docker.io   docker.io/pivotaldata/ubuntu                                        A quick freshening-up of the base Ubuntu d...   4                    
docker.io   docker.io/pivotaldata/ubuntu16.04-build                             Ubuntu 16.04 image for GPDB compilation         2                    
docker.io   docker.io/1and1internet/ubuntu-16-php-7.1                           ubuntu-16-php-7.1                               1                    [OK]
docker.io   docker.io/1and1internet/ubuntu-16-sshd                              ubuntu-16-sshd                                  1                    [OK]
docker.io   docker.io/pivotaldata/ubuntu-gpdb-dev                               Ubuntu images for GPDB development              1                    
docker.io   docker.io/smartentry/ubuntu                                         ubuntu with smartentry                          1                    [OK]
docker.io   docker.io/pivotaldata/ubuntu16.04-test                              Ubuntu 16.04 image for GPDB testing             0                    
==========
  • dockerコンテナをダウンロード

コマンドは docker pull イメージ名 を使用します

docker pull ubuntu
==========
[root@localhost ~]# docker pull ubuntu
Using default tag: latest
Trying to pull repository docker.io/library/ubuntu ... 
latest: Pulling from docker.io/library/ubuntu
83ee3a23efb7: Pull complete 
db98fc6f11f0: Pull complete 
f611acd52c6c: Pull complete 
Digest: sha256:703218c0465075f4425e58fac086e09e1de5c340b12976ab9eb8ad26615c3715
Status: Downloaded newer image for docker.io/ubuntu:latest
==========
  • ダウンロードしてきたイメージを確認
docker images
==========
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/ubuntu    latest              f63181f19b2f        34 hours ago        72.9 MB
==========
  • dockerコンテナの実行

コマンドは docker run オプション イメージID を使用します
イメージIDは↑で出力されている、 f63181f19b2f です。
オプションは -it でターミナル上での操作が可能です。

docker run -it f63181f19b2f
==========
[root@localhost ~]# docker run -it f63181f19b2f
root@04632dddfde1:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
root@04632dddfde1:~# 
==========
  • コンテナから抜ける

exit で抜けれます

root@04632dddfde1:~# exit
exit
[root@localhost ~]# 
  • dockerの状態を確認
docker ps -a
==========
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
04632dddfde1        f63181f19b2f        "/bin/bash"         6 minutes ago       Exited (0) 4 minutes ago                       naughty_keller
==========
  • dockerを停止

docker stop コンテナID で停止させることができます

docker stop 04632dddfde1
==========
[root@localhost ~]# docker stop 04632dddfde1
04632dddfde1
==========

勉強後イメージ

インストールしてコンテナを実行するまでしかできてないけど、案外簡単にできたかも?
次はコンテナ上でいろいろしてみたい

参考

3
3
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
3
3