運行linux的機器死機了_如何在任何機器上輕松運行任何Linux工具

運行linux的機器死機了

by Flavio De Stefano

由弗拉維奧·德·斯特凡諾(Flavio De Stefano)

如何在任何機器上輕松運行任何Linux工具 (How to easily run any Linux tool on any machine)

Have you ever encountered a situation like the ones below?

您是否遇到過以下情況?

Situation 1: You’re on your Linux workstation, and there is a PHP code that you must execute. But this code only runs under PHP 7, and your workstation only has PHP 5.

情況1 :您在Linux工作站上,必須執行一個PHP代碼。 但是此代碼僅在PHP 7下運行,而您的工作站只有PHP 5。

Situation 2: You’re working on your MacBook laptop, and you desperately need your sqlmap tool from your Kali Linux distribution. But you don’t have access to your Virtual Machine.

情況2 :您正在使用MacBook筆記本電腦,并且迫切需要Kali Linux發行版中的sqlmap工具。 但是您無權訪問虛擬機。

Situation 3: You’re on your Windows PC, and you immediately need an NGINX server that serves your static files from a directory.

情況3 :您在Windows PC上,立即需要一臺NGINX服務器,該服務器可從目錄中提供靜態文件。

Situation 4: No matter which platform, you have to start your Node.js 10 project. But you don’t have Node.js installed on your platform.

情況4 :無論使用哪個平臺,都必須啟動Node.js 10項目。 但是您沒有在平臺上安裝Node.js。

Or, in general, have you ever been a situation like this:

或者,總的來說,您是否遇到過以下情況:

Situation X: you are on one platform, and you immediately need a specific Linux tool, without altering your configuration or installing additional software.

情況X:您處于一個平臺上,并且立即需要特定的Linux工具,而無需更改配置或安裝其他軟件。

All these situations can be easily solved with a single tool you may have already heard about. It works without messing up your computer by installing additional software, or editing configurations that worked for a long time.

使用您可能已經聽說過的單個工具,可以輕松解決所有這些情況。 它可以通過安裝其他軟件或編輯長時間運行的配置而不會干擾計算機的工作。

Docker is an OS-level virtualization system. It can potentially run any binary you have in mind. Furthermore, it can run it in an isolated system, so it can’t touch your files and your precious working configurations.

Docker是操作系統級別的虛擬化系統。 它可以潛在地運行您想到的任何二進制文件。 此外,它可以在隔離的系統中運行它,因此它不會影響您的文件和寶貴的工作配置。

All you need is for someone to have already containerized your binary so that you can simply download it as an image. There are already a ton of Docker-built images out there waiting for you.

您需要做的就是讓某人已經將您的二進制文件容器化,以便您可以簡單地將其下載為映像。 已經有大量Docker構建的映像在等著您。

Docker does do more than this. It is a platform for developers and system administrators to develop, deploy, and run applications with containers. If you use it only to run your preferred binary, you’re using 1% of its features.

Docker所做的不只是此事。 它是開發人員和系統管理員使用容器開發,部署和運行應用程序的平臺。 如果僅使用它來運行首選的二進制文件,則使用的是其功能的1%。

But let’s start from the beginning.

但是,讓我們從頭開始。

You can install Docker on your machine by clicking this link and selecting your platform from left menu. Then, follow the guide.

您可以通過單擊此鏈接并從左側菜單選擇平臺來在您的計算機上安裝Docker。 然后,按照指南進行操作。

Once you have installed Docker, open your preferred Terminal or Command Prompt.

安裝Docker后,打開您的首選終端或命令提示符。

基本概念 (Basic concepts)

First of all, let’s test if your Docker configuration is working correctly. From the terminal:

首先,讓我們測試一下您的Docker配置是否正常工作。 從終端:

> docker --version
Docker version 18.03.0-ce, build 0520e24

If Docker is up and running, you should see your version number.

如果Docker已啟動并正在運行,則應該看到您的版本號。

All you need now is the docker run command.

您現在所需要的就是docker run命令。

The first thing to know is the name of the image you want to use. For official images, you usually have the name of the binary with no additions.

首先要知道的是您要使用的圖像的名稱。 對于官方圖像,通常使用二進制名稱,且不添加任何名稱。

For example, in the case of PHP, the image name is simply php. And what about the version? Simple as well, just add the version number (e.g., 7).

例如,對于PHP,映像名稱就是php。 那版本呢? 同樣簡單,只需添加版本號(例如7)。

Now let’s run our first container.

現在讓我們運行第一個容器。

情況1 (Situation 1)

You’re on your Linux workstation, and there is a PHP code that you must execute. But this code only runs under PHP 7, and your workstation only has PHP 5.
您在Linux工作站上,必須執行一個PHP代碼。 但是此代碼僅在PHP 7下運行,而您的工作站只有PHP 5。

Ok, now let’s imagine we have this simple code. It only works under PHP 7, because of the spaceship operator:

好的,現在讓我們假設我們有這個簡單的代碼。 由于太空飛船,它只能在PHP 7下工作 操作員:

<?php echo 1 <=> 0;

How we can execute this code with Docker? Let’s build our docker run command.

我們如何使用Docker執行此代碼? 讓我們構建我們的docker run命令。

> docker run -it php:7
Interactive shell
php > echo 1<=>0;
1

Yes — that’s all we need!

是的,這就是我們所需要的!

The extra part is the -it flag, but that’s not difficult. Since we are in the interactive shell, it simply specifies that this container should:

額外的部分是-it標志,但這并不困難。 由于我們位于交互式外殼中,因此只需指定該容器應:

  • -t ( — tty): allocate a pseudo-TTY

    -t ( — tty) :分配一個偽TTY

  • -i ( — interactive): keep STDIN open, even if not attached

    -i ( — interactive) :保持STDIN處于打開狀態,即使未連接也是如此

You should use them most of the time, with some exceptions.

除了某些例外,您應該大部分時間都使用它們。

情況二 (Situation 2)

You’re working on your MacBook laptop, and you desperately need your sqlmap tool from your Kali Linux distribution. But you don’t have access to your Virtual Machine.
您正在使用MacBook筆記本電腦,并且迫切需要Kali Linux發行版中的sqlmap工具。 但是您無權訪問虛擬機。

Unfortunately, sqlmap doesn’t have an official simple image name. But maybe someone else has created an image. Let’s search for it.

不幸的是,sqlmap沒有正式的簡單映像名稱。 但是也許其他人創造了形象。 讓我們搜索一下。

> docker search sqlmap
NAME                     DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
paoloo/sqlmap            Dockered sqlmap. Build instructions: https:/…   6
k0st/alpine-sqlmap       sqlmap on alpine (size: ~113 MB)                3                                       [OK]
jdecool/sqlmap           sqlmap (Automatic SQL injection) in a contai…   2                                       [OK]
harshk13/kali-sqlmap     Kali Linux base image with Sqlmap               1
marcomsousa/sqlmap       Simple image that execute Automatic SQL inje…   1                                       [OK]
....

We have several choices. This can happen often. For most cases, the image should be the first one (or the one with the greater star count).

我們有幾種選擇。 這可能經常發生。 在大多數情況下,該圖像應該是第一個(或具有較多星數的圖像)。

Let’s use it.

讓我們使用它。

> docker run -it paoloo/sqlmap --url http://localhost____ ___| |_____ ___ ___  {1.0.9.32#dev}
|_ -| . | |     | .'| . |
|___|_  |_|_|_|_|__,|  _||_|           |_|   http://sqlmap.org[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program.
...

All arguments that are after [docker run -it {image}] are passed to the binary executed in Docker, which is sqlmap in this case.

[docker run -it {image}]之后的所有參數 傳遞給在Docker中執行的二進制文件,在這種情況下為sqlmap。

Easy enough, right? Yes, but there is a con.

很容易,對吧? 是的,但是有一個缺點。

sqlmap writes log files onto the disk in the ~/.sqlmap path. But since Docker containers run in an isolated environment, we lose everything!!

sqlmap將日志文件寫到~/.sqlmap路徑中的磁盤上。 但是由于Docker容器在隔離的環境中運行,我們將失去一切!!

This is a feature, but in this case represents a bug for us — let’s fix it.

這是一項功能,但在這種情況下,對我們來說是一個錯誤-讓我們對其進行修復。

To enable persistence so that we don’t lose that log file, we have to create a bind mount between our workstation (host) and the Docker container.

為了啟用持久性以便不丟失該日志文件,我們必須在工作站(主機)和Docker容器之間創建綁定安裝。

Let’s decide that our host bind mount directory is /tmp/sqlmap. This should be an empty directory created only for this purpose!

讓我們決定我們的主機綁定安裝目錄是/tmp/sqlmap 。 這應該是一個僅為此目的而創建的空目錄!

> docker run -it -v \/tmp/sqlmap:/root/.sqlmap \paoloo/sqlmap \--url http://localhost

With the -v option we’ll create a bind mount. The first argument is the host path, and the second is the path on the container that we want to map.

使用-v選項,我們將創建綁定安裝。 第一個參數是主機路徑,第二個參數是我們要映射的容器上的路徑。

And, in fact, everything has been saved — including our reports.

而且,實際上,所有內容都已保存-包括我們的報告。

情況3 (Situation 3)

You’re on your Windows PC, and you immediately need an NGINX server that serves your static files from a directory.
您在Windows PC上,立即需要一臺NGINX服務器,該服務器可從目錄中提供靜態文件。

As you may have noticed, the first time you run docker run, it downloads the images from the Docker Hub.

您可能已經注意到,第一次運行docker run 它將從Docker Hub下載映像。

This could be hundreds of hundreds gigabytes. This is because we downloaded the tag latest of the image (the default).

這可能是數百個千兆字節。 這是因為我們下載了圖像的最新標簽(默認)。

But most images have also an ‘alpine’ version of the same image. It uses Linux Alpine OS. This is an optimized version of Linux, which occupies about 130MB.

但是大多數圖像也具有相同圖像的“高山”版本。 它使用Linux Alpine OS。 這是Linux的優化版本,占用約130MB。

Let’s use it in this situation. We know that image name upfront is nginx (since it is an official image).

讓我們在這種情況下使用它。 我們知道,圖像名稱的前期是nginx (因為它是官方圖像)。

So the final image name will be nginx:alpine. If you want a specific version (such as 1.14), use nginx:1.14-alpine.

因此,最終的圖像名稱將為nginx:alpine 如果需要特定版本(例如1.14),請使用nginx:1.14-alpine.

You may have more questions. How do we know which directory the NGINX container uses to serve our files? How we know which port it exposes?

您可能還有其他問題。 我們如何知道NGINX容器使用哪個目錄來提供文件? 我們如何知道它暴露哪個端口?

Luckily, the answers to all your questions are in the Docker Hub.

幸運的是,所有問題的答案都在Docker Hub中 。

So, to recap:

因此,回顧一下:

  • We have to share our directory to serve into the container. Again, this can be done using bind mounts: -v $(pwd):/usr/share/nginx/html

    我們必須共享目錄才能投放到容器中。 同樣,這可以使用綁定掛載完成: -v $(pwd):/usr/share/nginx/html

  • By adding :ro at the end, we are sure that container uses our files in read-only mode.

    通過在末尾添加:ro ,可以確保容器以只讀模式使用文件。

  • We must bind the port exposed by the container to the host, and then communicate via TCP on our host: -p 80:80

    我們必須將容器公開的端口綁定到主機,然后在主機上通過TCP進行通信-p 80:80

> docker run \-v $(pwd):/usr/share/nginx/html:ro \-p 80:80 \nginx:alpine

情況4 (Situation 4)

No matter which platform, you have to start your Node.js 10 project. But you don’t have Node.js installed on your platform.
無論使用哪種平臺,都必須啟動Node.js 10項目。 但是您沒有在平臺上安裝Node.js。

Perhaps you now understand how it works. Here, we have to share our content and bind ports.

也許您現在了解它是如何工作的。 在這里,我們必須共享我們的內容并綁定端口。

However, we don’t know the container working directory. Instead, we’re gonna explicitly set it with the -w flag to a custom directory of our choice. For example, you might choose/src — just don’t override an existing directory!

但是,我們不知道容器的工作目錄。 相反,我們將使用-w標志將其顯式設置為我們選擇的自定義目錄。 例如,您可以選擇/src只是不覆蓋現有目錄!

> docker run \-p 3000:3000 \-v $(pwd):/src \-w /src \node:10-alpine \node main.js
Example app listening on port 3000!
...

Simple and powerful enough?

簡單而強大?

Additionally, do you want a ‘shortcut’ to just execute binaries without searching for third-party images?

另外,您是否希望“快捷方式”僅執行二進制文件而不搜索第三方圖像?

Why don’t you try my simple tool DR?

您為什么不嘗試使用我的簡單工具DR ?

I hope that you’re gonna use Docker for all your future binaries! :)

希望您將來使用Docker編寫所有二進制文件! :)

翻譯自: https://www.freecodecamp.org/news/how-to-run-any-binary-of-any-platform-without-messing-up-with-your-workstation-dade18c18801/

運行linux的機器死機了

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392721.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392721.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392721.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【實戰】爛泥:一次糾結的系統安裝

這應該是昨天的事了&#xff0c;因為昨天太忙了&#xff0c;就沒有貼出來&#xff0c;今天下午我想了想還是貼出來吧。一是給自己一個提醒&#xff0c;二是也給壇子里面的午飯們再以后安裝系統中提供一種思路。 環境&#xff1a;thinkpad x100e筆記本&#xff0c;2G內存&#x…

Android動態改變TextView字體顏色

Android動態改變TextView字體顏色 分類&#xff1a; Android 2012-06-04 21:56 141人閱讀 評論(0) 收藏 舉報androidcolorslayout必須在在res/color文件夾下面創建一個selector的xml [html] view plaincopyfont_style_colors.xml <selector xmlns:android"http://…

關于小程序的一些坑的總結

最近開發的小程序&#xff0c;有很多的坑。 1.底部的tabbar 不可更改尺寸和字體的大小。限制的還是蠻死的&#xff01;不知道是不是我沒找到方法去修改還是咋的。淡淡的憂桑&#xff5e;&#xff5e;&#xff5e; 2.可以動態的設置小程序的頂部導航欄的字&#xff0c;但是不可…

開源項目貢獻者_如何認識您的開源項目貢獻者并發展您的社區

開源項目貢獻者by David Herron大衛赫倫(David Herron) 如何認識您的開源項目貢獻者并發展您的社區 (How to recognize your open source project contributors and grow your community) There’s a truism — if a community is not growing, it is slowly dying. How is yo…

華農java實驗7_國家實驗教學示范中心

我校有生物學實驗教學中心、作物學實驗教學中心、水產養殖實驗教學中心、動物醫學實驗教學中心4個國家級實驗教學示范中心&#xff0c;10個省級實驗教學示范中心。生物學實驗教學中心華中農業大學生物學實驗教學中心成立于2001年7月&#xff0c;是直屬于生命科學技術學院的校級…

jsonpickle數據序列化

json&pickle數據序列化 json 用于字符串和python數據類型間進行轉換 pickle 用于python特有的類型 和 python的數據類型間進行轉換序列化&#xff1a;把字典或者字符串的內存對象 存到硬盤上&#xff1b; 反序列化&#xff1a;就是從硬盤上加載出來 json序列化與反序列化…

array_walk與array_map的區別

1.array_walk是用于用戶自定義的函數&#xff0c;所以想用array_walk($aIds, "trim");去掉數據元素中的空格是達不到目的的只能用array_walk($aIds, create_function(&$val, $val trim($val);)); 2.想完成上邊的需求其實更加合適用$aNewIds array_map("t…

shopify二次開發教程_詳細教程:如何將Shopify的Storefront API與React和Redux結合使用...

shopify二次開發教程by Chris Frewin克里斯弗里溫(Chris Frewin) 詳細教程&#xff1a;如何將Shopify的Storefront API與React和Redux結合使用 (A detailed tutorial: how to use Shopify’s Storefront API with React and Redux) 電子商務為所有人&#xff01; (…網站&…

element里面popover里面的高度_五斗柜的高度一般是多少 五斗柜放在什么位置好

五斗柜也就是一種抽屜收納柜&#xff0c;目前在臥室或是書房等空間均是可以見到。其根據使用用途的不同&#xff0c;進而有著高度和款式&#xff0c;以及擺放位置等等的區別。因此&#xff0c;下面帶來五斗柜的高度一般是多少、五斗柜放在什么位置好&#xff0c;以及五斗柜里面…

leetcode 57. 插入區間

給出一個無重疊的 &#xff0c;按照區間起始端點排序的區間列表。 在列表中插入一個新的區間&#xff0c;你需要確保列表中的區間仍然有序且不重疊&#xff08;如果有必要的話&#xff0c;可以合并區間&#xff09;。 示例 1&#xff1a; 輸入&#xff1a;intervals [[1,3]…

《C++標準程序庫》學習筆記1--第二章第三章

————————— 第二章 —————————1.&#xff08;P11&#xff09; C規定&#xff1a;除了以typename修飾外&#xff0c;template內的任何標志符號都被視為一個值(value)而非一個型別。 eg. template <classT>classMyClass{ typename T::SubType *ptr; };…

讓物聯網真正起飛的關鍵:無線充電

從一般郊區家庭到工廠裝配生產線&#xff0c;我們生活中的每個角落都正在經歷“智能”技術強化的過程。物聯網&#xff08;IoT&#xff09;技術看似無所不在&#xff0c;但是為這些裝置持續供電仍是一大挑戰&#xff0c;除非這個問題能夠解決&#xff0c;否則許多令人興奮的物聯…

【NOIP2016】憤怒的小鳥

題目描述 Kiana最近沉迷于一款神奇的游戲無法自拔。 簡單來說&#xff0c;這款游戲是在一個平面上進行的。 有一架彈弓位于(0,0)處&#xff0c;每次Kiana可以用它向第一象限發射一只紅色的小鳥&#xff0c;小鳥們的飛行軌跡均為形如的曲線&#xff0c;其中a,b是Kiana指定的參數…

leetcode 127. 單詞接龍(bfs)

給定兩個單詞&#xff08;beginWord 和 endWord&#xff09;和一個字典&#xff0c;找到從 beginWord 到 endWord 的最短轉換序列的長度。轉換需遵循如下規則&#xff1a; 每次轉換只能改變一個字母。 轉換過程中的中間單詞必須是字典中的單詞。 說明: 如果不存在這樣的轉換序…

java swing 動態生成表格_6 個曾經牛逼哄哄的 Java 技術,你用過嗎?

大家好啊&#xff0c;今天給大家分享下我的開發歷程中&#xff0c;我知道的那些被淘汰的技術或者框架&#xff0c;有些我甚至都沒有用過&#xff0c;但我知道它曾經風光過。廢話不多說&#xff0c;下面我要開始吹了……1、Swing下面這個是用 swing 開發的&#xff1a;Swing 算是…

如果您是JavaScript開發人員,為什么要進行增強現實-以及如何開始

by Evaristo Caraballo通過Evaristo Caraballo 如果您是JavaScript開發人員&#xff0c;為什么要進行增強現實-以及如何開始 (Why you should do Augmented Reality if you are a JavaScript developer — and how to start) If you are a JavaScript coder who is still late…

[Java 安全]加密算法

Base64編碼 算法簡述 定義 Base64內容傳送編碼是一種以任意8位字節序列組合的描述形式&#xff0c;這種形式不易被人直接識別。 Base64是一種很常見的編碼規范&#xff0c;其作用是將二進制序列轉換為人類可讀的ASCII字符序列&#xff0c;常用在需用通過文本協議&#xff08;比…

hdu5299 Circles Game

題意是這樣。給出非常多圓&#xff0c;要么兩兩相離&#xff0c;要么包括&#xff0c;若刪掉一個圓&#xff0c;那被他包括的都要刪除&#xff0c;若某人沒有圓給他刪&#xff0c;那么他就贏了。 。。。知道樹上博弈的話。就非常easy。。。不知道的話。這確實是個神題…… 按半…

leetcode 1356. 根據數字二進制下 1 的數目排序(排序)

給你一個整數數組 arr 。請你將數組中的元素按照其二進制表示中數字 1 的數目升序排序。 如果存在多個數字二進制中 1 的數目相同&#xff0c;則必須將它們按照數值大小升序排列。 請你返回排序后的數組。 示例 1&#xff1a; 輸入&#xff1a;arr [0,1,2,3,4,5,6,7,8] 輸…

oracle java認證_如何通過Oracle的Java認證-開發人員實用指南

oracle java認證by javinpaul由javinpaul 如何通過Oracle的Java認證-開發人員實用指南 (How to Pass Oracle’s Java Certifications — a Practical Guide for Developers) A Java certification is highly regarded in the IT Industry and provides a Java developer with …