Sign inSign up

matjaz99/hello-php

By matjaz99

•Updated about 7 years ago

This is my first repo and my first image

Image
0

232

matjaz99/hello-php repository overview

Create PHP based image:

$ mkdir hello-php $ cd hello-php $ mkdir src

$ vi src/index.php

Hello PHPā€; echo "
"; echo "Container ID: ".gethostname(); ?>

$ vi Dockerfile FROM php:7.0-apache COPY src/ /var/www/html EXPOSE 80

Build image:

$ docker build -t hello-php .

Run:

$ docker run -d --name hello-php -p 8888:80 hello-php

Tag the image (first login):

$ docker login Username: Password:

$ docker tag hello-php matjaz99/hello-php:1.0

Push to repo:

$ docker push matjaz99/hello-php:1.0

Creating service

Prepare docker-compose.yml (i also added visualization tool - optional)

version: "3" services: web: # replace username/repo:tag with your name and image details image: matjaz99/hello-php:1.0 deploy: replicas: 5 resources: limits: cpus: "0.1" memory: 50M restart_policy: condition: on-failure ports: - "8888:80" networks: - webnet visualizer: image: dockersamples/visualizer:stable ports: - "8889:8080" volumes: - "/var/run/docker.sock:/var/run/docker.sock" deploy: placement: constraints: [node.role == manager] networks: - webnet networks: webnet:

Deploy:

$ docker stack deploy -c docker-compose.yml hello-php

$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS lf3m8dk2wnp9 hello-php_web replicated 5/5 matjaz99/hello-php:1.0 *:8888->80/tcp

$ docker service ps hello-php_web ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 8t6310n7xo0w hello-php_web.1 matjaz99/hello-php:1.0 docker-1 Running Running 2 minutes ago ceha84p2hup5 hello-php_web.2 matjaz99/hello-php:1.0 docker-2 Running Running 4 minutes ago oiz8jqb1e8ez hello-php_web.3 matjaz99/hello-php:1.0 docker-1 Running Running 2 minutes ago ctr17dvtjykx hello-php_web.4 matjaz99/hello-php:1.0 docker-1 Running Running 2 minutes ago wso29iaajqtz hello-php_web.5 matjaz99/hello-php:1.0 docker-2 Running Running 4 minutes ago

Run several times (notice that different container was called each time - load balancing):

$ curl -4 http://localhost:8888⁠

Check visualizer on:

http://192.168.26.219:8889/⁠

Stop deployed service:

$ docker stack rm hello-php

Tag summary

Content type

Image

Digest

Size

127.2 MB

Last updated

about 7 years ago

docker pull matjaz99/hello-php:2.0.1