Code Monkey home page Code Monkey logo

docker-demo's Introduction

docker-demo

About

Docker勉強会のデモ用コード

Environment

Info

  • Docker for Windows/Macでも可

Demo

1. Dockerイメージのpull

nginx のDockerイメージをDockerHubからpullする

$ docker pull nginx

nginxのイメージがpullできているか確認

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              568c4670fa80        2 weeks ago         109MB

2. Dockerコンテナの作成

pullしたnginxを起動する

$ docker run \
    -p 8080:80 \
    -d \
    nginx

-p : ホストの8080ポートへ、起動したコンテナの80ポートをフォワードさせる
-d : バックグラウンドで実行
nginx : 起動するイメージ名

3. nginxが起動できているか確認

localhost:8080 へアクセスし、nginxが起動できているか確認

$ curl -I localhost:8080
HTTP/1.1 200 OK
Server: nginx/1.15.7
Date: Tue, 18 Dec 2018 20:53:38 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 27 Nov 2018 12:31:56 GMT
Connection: keep-alive
ETag: "5b393c-264"
Accept-Ranges: bytes

4. Dockerfileからイメージの作成

GitHubから当該リポジトリをクローン

$ git clone https://github.com/y-ohgi/docker-demo
$ cd docker-demo/php

php/Dockerfile をもとにDockerイメージをビルド

$ docker build \
    -t myphp \
    .

-t : Dockerイメージ名 . : コンテキストとなるディレクトリを指定

5. 作成したイメージの実行

$ docker run \
    -p 9000:9000 \
    -d \
    myphp

localhost:9000/phpinfo.php へアクセスし、PHPが起動できているか確認
同時にPDOがインストールされているかも確認する

Tips

起動したコンテナを停止

# 起動中のコンテナを確認
$ docker ps

# 全てのコンテナを停止
$ docker stop $(docker ps -aq)

# コンテナの停止を確認
$ docker ps

手前味噌

y-ohgi/dockerfiles

docker-demo's People

Contributors

y-ohgi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.