1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

“Docker" First Try (1)

Last updated at Posted at 2019-08-03

■Environments
<AWS>
EC2:t2.micro

<Instelled Docker version>

$ docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a215d7133c34aa18e3b72b4a21fd0c6136
 Built:             Mon Jul  1 18:51:44 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a/18.06.1-ce
  Built:            Mon Jul  1 18:53:20 2019
  OS/Arch:          linux/amd64
  Experimental:     false//

$ docker-compose version
docker-compose version 1.24.1, build 4667896b
docker-py version: 3.7.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j  20 Nov 2018

■Let's TRY

(1)Pull Ubuntu(ubuntu:16.04) images from repository
*"Pull" command will download images from Docker repository

$ docker pull ubuntu:16.04
16.04: Pulling from library/ubuntu
f7277927d38a: Pull complete 
8d3eac894db4: Pull complete 
edf72af6d627: Pull complete 
3e4f86211d23: Pull complete 
Digest: sha256:97b54e5692c27072234ff958a7442dde4266af21e7b688e7fca5dc5acc8ed7d9
Status: Downloaded newer image for ubuntu:16.04

(2)Create Container @ bash from images

$ docker run -d -it ubuntu:16.04 bash

Confirmed containor by "ps" command
*"ps" will show all container at docker host

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
4173f3027999        ubuntu:16.04        "bash"              About a minute ago   Up About a minute                       dreamy_elion

(3)Run & modify existed container

$ docker exec -it 4173f3027999 bash
root@4173f3027999:/# apt-get update && apt-get install -y php

(4)Created new image from "commit",then added tag

$ docker commit  4173f3027999
sha256:f669c3195c60707a2ade86107f3f3a4a01aac99f41dbe55b3396037167734bb2
$ docker tag f669c3195c607 sampledocker
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
sampledocker        latest              f669c3195c60        About a minute ago   203MB
ubuntu              16.04               5e13f8dd4c1a        10 days ago          120MB

(4)Copy local file to Docker Container

$ touch samplefile
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
4173f3027999        ubuntu:16.04        "bash"              17 minutes ago      Up 17 minutes                           dreamy_elion
$ docker cp samplefile 4173f3027999:/
$ docker exec 4173f3027999 bash -c 'ls -al /'
total 4
drwxr-xr-x   1 root root  102 Aug  3 10:32 .
drwxr-xr-x   1 root root  102 Aug  3 10:32 ..
-rwxr-xr-x   1 root root    0 Aug  3 10:14 .dockerenv
drwxr-xr-x   1 root root   19 Aug  3 10:20 bin
drwxr-xr-x   2 root root    6 Apr 12  2016 boot
drwxr-xr-x   5 root root  360 Aug  3 10:14 dev
drwxr-xr-x   1 root root 4096 Aug  3 10:20 etc
drwxr-xr-x   2 root root    6 Apr 12  2016 home
drwxr-xr-x   1 root root   45 Sep 13  2015 lib
drwxr-xr-x   2 root root   34 Jul 20 13:50 lib64
drwxr-xr-x   2 root root    6 Jul 20 13:50 media
drwxr-xr-x   2 root root    6 Jul 20 13:50 mnt
drwxr-xr-x   2 root root    6 Jul 20 13:50 opt
dr-xr-xr-x 100 root root    0 Aug  3 10:14 proc
drwx------   1 root root   27 Aug  3 10:21 root
drwxr-xr-x   1 root root   21 Jul 20 13:50 run
-rw-rw-r--   1 1000 1000    0 Aug  3 10:31 samplefile
drwxr-xr-x   1 root root   21 Jul 23 15:22 sbin
drwxr-xr-x   2 root root    6 Jul 20 13:50 srv
dr-xr-xr-x  13 root root    0 Aug  3 10:14 sys
drwxrwxrwt   1 root root    6 Aug  3 10:19 tmp
drwxr-xr-x   1 root root   66 Jul 20 13:50 usr
drwxr-xr-x   1 root root   41 Jul 20 13:51 var

(5)Stop container

$ docker stop 4173f3027999
4173f3027999
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

*ps -a will show stopped container

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
4173f3027999        ubuntu:16.04        "bash"              20 minutes ago      Exited (0) 32 seconds ago                       dreamy_elion
1
0
1

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?