Use Docker to build swoole development environment under MAC system

Source: Internet
Author: User
Tags docker run
As an open-source framework for redefining PHP, Swoole allows PHP to be applied to more scenarios.

For a PHP programmer, the swoole can be used to understand programming methods that have never been touched before.

As we all know, building a development environment is actually a very troublesome thing, often encounter a variety of problems. So I built a set of swoole environments with Docker, and by this tutorial, it was very easy to start a swoole trip.

The first is to install Docker, the official website has detailed installation steps: https://docs.docker.com/mac/step_one/

Mac users can refer to the above URLs. For other users of the system, the official website has a corresponding method. No more detail here.

The following steps are also based on the Mac system.

After the installation is complete, you will see the application of the name Docker Quickstart Terminal in Launchpad, and when clicked, it will open the system's default terminal, and then wait a moment to see the whale's portrait appear.

Be aware of a message in the terminal:

Docker is configured to use the default machine with IP 192.168.99.100

Remember this IP address that we use when we access the container.

In order to verify that Docker is running, enter the following command in the Open terminal:

Docker images

If Docker does not run correctly, you will see the following error message:

Cannot connect to the Docker daemon. Is the Docker daemon running on this host?

After making sure Docker is running correctly, enter the following command to get the Swoole image:

Docker Pull Koolob/swoole-docker

This image is built on a php:5.6-cli-based image, including the latest version of Swoole 1.8.4, which is compiled by default with the following compilation parameters:

--enable-async-redis--enable-async-httpclient--enable-openssl--enable-jemalloc

Swoole Compilation parameter Description: http://wiki.swoole.com/wiki/page/437.html

This image of the dockerfile is open source, there is a need to build a custom environment of friends can refer to my dockerfile file for modification: Github

Once the image is downloaded, you can run a container and enter the Swoole environment.

Enter the command:

Docker Run-t-I Koolob/swoole-docker/bin/bash

It is then entered into the container.

Re-enter:

Php-r ' echo swoole_version (). " \ n ";"

You can see that the output is 1.8.4, which is the version number of the current swoole.

So we have a swoole environment built with Docker.

Next, we can build the code and environment into a mirror to run. There is still an example to refer to:

git clone https://github.com/koolob/swoole-docker-example.git

After downloading, switch to the directory and execute directly

./build.sh

Then the browser access address: http://192.168.99.100:8080/can see the results, but also in the terminal can see the contents of the program output. Use CTRL + C in the terminal to exit the container.

192.168.99.100 This IP is the IP of the terminal hint mentioned above

We are running a very simple HTTP service with the code located under the SRC folder:

$serv = new Swoole_http_server ("0.0.0.0", 8080), $serv->on (' Request ', function ($request, $response) {    var_dump ( $request->get);    Var_dump ($request->post);    Var_dump ($request->cookie);    Var_dump ($request->files);    Var_dump ($request->header);    Var_dump ($request->server);    $response->cookie ("User", "Swoole");    $response->header ("X-server", "Swoole");    $response->end ("

Hello swoole!

");}); $serv->start ();

What the build.sh script does is build the image and start a container.

The newly built image is also simple, based on the Koolob/swoole-docker, open 8080 port, copy the contents of the SRC directory into the Mirror, and execute PHP code while the container is running.

The next thing to do is to modify the code in SRC, execute the build.sh script, and then test.

At this point, our swoole development environment has been built.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.