我想使用以下内容将一些预定义的文本写入文件:
text="this is line one\n
this is line two\n
this is line three"
echo -e $text > filename
Run Code Online (Sandbox Code Playgroud)
我期待这样的事情:
this is line one
this is line two
this is line three
Run Code Online (Sandbox Code Playgroud)
但得到了这个:
this is line one
this is line two
this is line three
Run Code Online (Sandbox Code Playgroud)
我很肯定每个人都没有空间\n,但额外的空间是如何产生的?
我知道默认情况下,docker会创建一个虚拟网桥docker0,并且所有容器网络都会链接到docker0.

如上图所示:
eth0配对vethXXXvethXXX链接到docker0与交换机链接的机器相同但是docker0和东道主之间的关系是什么eth0?进一步来说:
问题2可能有点令人困惑,我会把它保留在那里并解释一下:
eth0.如何转发到容器?我的意思是,必须有一些地方存储信息,我该如何检查?提前致谢!
在阅读了答案和官方网络文章后,我发现下面的图表更准确,docker0并且eth0没有直接链接,而是可以转发数据包:
http://dockerone.com/uploads/article/20150527/e84946a8e9df0ac6d109c35786ac4833.png
kube-proxy有一个名为--proxy-mode的选项,根据帮助消息,这个选项可以是userspace或iptables.(见下文)
# kube-proxy -h
Usage of kube-proxy:
...
--proxy-mode="": Which proxy mode to use: 'userspace' (older, stable) or 'iptables' (experimental). If blank, look at the Node object on the Kubernetes API and respect the 'net.experimental.kubernetes.io/proxy-mode' annotation if provided. Otherwise use the best-available proxy (currently userspace, but may change in future versions). If the iptables proxy is selected, regardless of how, but the system's kernel or iptables versions are insufficient, this always falls back to the userspace …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用while循环将对象添加到列表中.
这基本上就是我想做的事情:
class x:
pass
choice = raw_input(pick what you want to do)
while(choice!=0):
if(choice==1):
Enter in info for the class:
append object to list (A)
if(choice==2):
print out length of list(A)
if(choice==0):
break
((((other options))))
Run Code Online (Sandbox Code Playgroud)
我可以将对象添加到列表中,但我仍然坚持如何在循环中向列表中添加多个对象.
这是我到目前为止的代码:
print "Welcome to the Student Management Program"
class Student:
def __init__ (self, name, age, gender, favclass):
self.name = name
self.age = age
self.gender = gender
self.fac = favclass
choice = int(raw_input("Make a Choice: " ))
while (choice !=0):
if (choice==1):
print("STUDENT")
namer …Run Code Online (Sandbox Code Playgroud) 每当我发现一些令人困惑的命令时,我都会联系MAN页面.有时我会得到我想要的东西,但大多数情况下我更加困惑.
我理解man page分为几个部分:NAME等等.但我不知道所有选项意味着什么,比如每个选项应该有多少个参数,它们的依赖性等等.
有人可以帮我澄清一下吗?
这有什么文件吗?
在开发golang http应用程序时,我使用http.Request了很多.当访问请求主机地址时,我会使用req.Host,但我发现有req.URL.Host字段,但是当我打印它时,它是空的.
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("uri Host: " + r.URL.Host + " Scheme: " + r.URL.Scheme)
fmt.Println("Host: " + r.Host)
}
Run Code Online (Sandbox Code Playgroud)
http.Request的文档给出了以下注释,但net/url没有提供太多线索.
// For server requests Host specifies the host on which the
// URL is sought. Per RFC 2616, this is either the value of
// the "Host" header or the host name given in the URL itself.
// It may be of the form "host:port". For …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个侦听IPv4和IPv6地址的Web服务器.但是,我最初写的代码不起作用.然后我发现IPv6结构适用于IPv4和IPv6.所以现在我使用IPv6结构,但只有IPv4地址可以工作.这篇文章,为什么我不能将ipv6套接字绑定到一个linklocal地址,其中说添加server.sin6_scope_id = 5;所以我这样做但它仍然不接受IPv6 telnet连接.任何帮助将不胜感激,因为我彻底难倒.
谢谢!
我的代码如下:
void initialize_server(int port, int connections, char* address)
{
struct sockaddr_in6 socket_struct;
/*Creates the socket*/
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
syslog(LOG_ERR, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
}/*Ends the socket creation*/
/*Populates the socket address structure*/
socket_struct.sin6_family = AF_INET6;
if(address == NULL)
socket_struct.sin6_addr=in6addr_any;
else
{
inet_pton(AF_INET6, "fe80::216:3eff:fec3:3c22", (void *)&socket_struct.sin6_addr.s6_addr);
}
socket_struct.sin6_port =htons(port);
socket_struct.sin6_scope_id = 0;
if (bind(sock_fd, (struct sockaddr*) &socket_struct, sizeof(socket_struct)) < 0)
{
syslog(LOG_ERR, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
}//Ends the …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置 Webpack 以与 docker 一起运行。我希望将其放入自己的容器中,构建文件,然后 nginx 将在其容器上提供生成的代码。
我的docker-compose.yml文件如下所示:
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
php:
build: ./php/
expose:
- 9000
links:
- mysql
volumes_from:
- app
app:
image: php:7.0-fpm
volumes:
- ./app/symfony:/var/www/html
command: "true"
web:
build: ./webpack
volumes_from:
- app
mysql:
image: mysql:latest
volumes_from:
- data
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
data:
image: mysql:latest
volumes:
- /var/lib/mysql
command: "true"
Run Code Online (Sandbox Code Playgroud)
我的代码存储在该app/symfony目录中。webpack 容器的 Dockerfile 当前为:
FROM node:wheezy
WORKDIR …Run Code Online (Sandbox Code Playgroud) Python为instance/class属性提供了许多可能性,例如:
class A(object):
def __init__(self):
self.foo = "hello"
a = A()
Run Code Online (Sandbox Code Playgroud)
有很多方法可以访问/更改以下值self.foo:
a.fooa.__dict__['foo']a.__get__和a.__set__,当然有两个是预先定义的方法.a.__getattribute____getattr__ 和 __setattr__在阅读源代码时,我总是迷失在他们最终的访问顺序之下?当我使用时a.foo,我如何知道实际调用哪个方法/属性?
我理解在python中,无论何时访问类/实例变量,它都会调用__getattribute__方法来获取结果.但是我也可以obj.__dict__['x']直接使用,得到我想要的东西.
我有点困惑有什么区别?当我使用时getattr(obj, name),是在呼叫__getattribute__还是在obj.__dict__[name]内部?
提前致谢.